Topic: Link_to_remote and onmouseover

Can you add a onmouseover to a link_to_remote? And an id on the link?

Re: Link_to_remote and onmouseover

link_to_remote is designed for onclick, but a helper function may be used.

http://www.mail-archive.com/rubyonrails … 03620.html

Re: Link_to_remote and onmouseover

dvohra wrote:

link_to_remote is designed for onclick, but a helper function may be used.

http://www.mail-archive.com/rubyonrails … 03620.html

This is really confusing, and the bad side om Rails

Re: Link_to_remote and onmouseover

Its actually simpler than it appears. HTML attributes like :class, :onmouseover can simply be dropped in after the other non-attribute options (:url, :loading, :update, :complete) etc. The only gotcha is options and html_options must be kept in seperate hashes (so sure enough, the example you found was wrong):

# This will NOT work, because rails thinks onmouseover is part of the normal options
link_to_remote("Example", :url => {:a => "b"}, update => {:d => "e"}, onmouseover => "alert('hi')")

# This will work because we've seperated options and html_options. Rails is happy again
link_to_remote("Example", {:url => {:a => "b"}, update => {:d => "e"}}, {onmouseover => "alert('hi')"})


Hope that helps smile

Alex

Last edited by alexpt (2007-06-11 12:53:18)

Re: Link_to_remote and onmouseover

alexpt wrote:

Its actually simpler than it appears. HTML attributes like :class, :onmouseover can simply be dropped in after the other non-attribute options (:url, :loading, :update, :complete) etc.

Alex

As far as I know, Alex is right, so that may suit your needs just fine.

Just a side note, but you may want to check out Dan Webb's UJS for Rails plugin (www.ujs4rails.com) though, which allows for unobtrusive javascript with very similar view helpers. I haven't used the UJS plugin, but reading through the documentation and examples it seems very interesting. I'm a fan of unobtrusive javascript, so I just thought I'd give you a heads up.

.phil.

Re: Link_to_remote and onmouseover

alexpt wrote:

Its actually simpler than it appears. HTML attributes like :class, :onmouseover can simply be dropped in after the other non-attribute options (:url, :loading, :update, :complete) etc. The only gotcha is options and html_options must be kept in seperate hashes (so sure enough, the example you found was wrong):

# This will NOT work, because rails thinks onmouseover is part of the normal options
link_to_remote("Example", :url => {:a => "b"}, update => {:d => "e"}, onmouseover => "alert('hi')")

# This will work because we've seperated options and html_options. Rails is happy again
link_to_remote("Example", {:url => {:a => "b"}, update => {:d => "e"}}, {onmouseover => "alert('hi')"})


Hope that helps smile

Alex

Great. It helps a lot. But a few additional questions. Can you leave the parenthesis out? And what about the :a and update, shouldn't be :action and :update?

Re: Link_to_remote and onmouseover

Hi palib,

Yes sorry update should be :update, that was a typo wink And as for :a :d, I just did that to save space, but they would be the proper parameters.

No you don't need the parentheses, I'm just rather fond of them. And in case you're interested a couple of related synactical sugarcubes:

- Some people like to split different options onto different lines:

link_to_remote "Example", 
               {:url => {:a => "b"},
               :update => {:d => "e"}},
               onmouseover => "alert('hi')"

- Some people like to explicitly define when html_options start, rather than creating two seperate hashes
link_to_remote "Example", :url => {:a => "b"}, update => {:d => "e"}, html_options => {onmouseover => "alert('hi')"}

Both of these will do exactly the same thing, its really what is most readable to you.

Alex

Re: Link_to_remote and onmouseover

alexpt wrote:

Hi palib,

Yes sorry update should be :update, that was a typo wink And as for :a :d, I just did that to save space, but they would be the proper parameters.

No you don't need the parentheses, I'm just rather fond of them. And in case you're interested a couple of related synactical sugarcubes:

- Some people like to split different options onto different lines:

link_to_remote "Example", 
               {:url => {:a => "b"},
               :update => {:d => "e"}},
               onmouseover => "alert('hi')"

- Some people like to explicitly define when html_options start, rather than creating two seperate hashes
link_to_remote "Example", :url => {:a => "b"}, update => {:d => "e"}, html_options => {onmouseover => "alert('hi')"}

Both of these will do exactly the same thing, its really what is most readable to you.

Alex

Thanks. Very helpful.

Re: Link_to_remote and onmouseover

Hi,

I have a problem since some days. I want to change div-layers with onmouseover. At the moment it runs via click. Here is a scheme from my project. I'm using link_to_remote because I'm changing the div's with ajax effects from the script.aculo.us files.

What I wanna know: How can I change (hidden) div's with onmouseover?
It doesn't have to be like i did. It would be great if you could help me solve this problem :-)

Greetings from germany

Chris


-------


app/views/layouts/standard.rhtml

<%= link_to_remote('Jobs', {:url => {:controller => 'website', :action => 'jobs'}}, {:class => 'cloud1a'}) %>

...

<%=    render(:partial => 'jobs') %>


app/views/website/_jobs.rhtml
<div style="display:none;position:relative;width:95%;" id="jobs">
..some content..
</div>

app/views/website/jobs.rjs
...
page.visual_effect :fade, 'about_us'
...
page.delay(1) do
    page.visual_effect :appear, 'jobs'
end

Re: Link_to_remote and onmouseover

@peburrows (and @palb) word on the unobtrusive advice. the link's so nice . . . we post it twice: http://www.ujs4rails.com/resources/usage-documentation

for a background on why this seems like a good thing to so many people, check the behaviour files:
http://www.bennolan.com/behaviour/  You could write your own library to do this if you wanted too.