How to make a word act as a button?

Hi, I’d like to know how can I make a link to a method. I mean, not a
link
that would normally render a new page, but something that looks like a
link
(a blue word) but triggers one of my class methods like show a photo at
the
right side of my website or hide it if clicked again.

Thank you

Hey Rodrigo,

I see that you are asking a lot of questions lately and so I thought I
would give you a few links to read which should help you down the road:

http://guides.rubyonrails.org/

Start with the guides above. It will help you out a lot with
understanding some of the basics with rails.

http://railscasts.com/

Then visit railscasts and Ryan B. has some wonderful videos you can
watch on many different subjects. This will definitely help you down
the road. His site has been recently updated so you can now watch the
movies, or read the entire movie via text.

Enjoy.

On Jun 6, 2011, at 2:46 PM, Rodrigo R. wrote:

Hi, I’d like to know how can I make a link to a method. I mean, not a link that
would normally render a new page, but something that looks like a link (a blue
word) but triggers one of my class methods like show a photo at the right side of
my website or hide it if clicked again.

Thank you

For this you would normally use JavaScript. I’d recommend reading up at
Mozilla Developer Network: https://developer.mozilla.org/en-US/learn.

Basically you’ll register an ‘onclick’ handler on the link and in that
function, change the display style of the photo. For instance:

HTML:


Show Picture

JavaScript (index.js):
var link = document.getElementById(“show-link”);
if (link) {
link.onclick = function(event) {
var picture = document.getElementById(“my-picture”);
if (picture) {
if (picture.style.display == “none”) {
picture.style.display = “inline”;
} else {
picture.style.display = “none”;
}
}
};
}

Rails provides a helper method for doing just that:
http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-link_to_function.
You’ll still need to write the JavaScript to fetch and display the
photo
though.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs