user938363
user938363

Reputation: 10350

How to trigger another event when clicking a link in rails 3.1?

This question may be raised many time here. I would like to trigger another event when clicking a link on rails view. Something like:

<%= link_to 'Referesh', event, :onclick => 'another_event' %>

I have another_event as a ruby method called url_handler with two params index and url. Can I do something like below?

<%= link_to 'Customer', customers_path, :onclick => '/url_handler?index=1&url=user_menus_path' %>

Or if not, how to implement this trigger?

Upvotes: 0

Views: 441

Answers (1)

tadman
tadman

Reputation: 211560

You probably mean to use link_to with the :remote => true flag set because the :onclick option is expecting JavaScript that will be inlined into the resulting HTML.

You must also have a route to that method to be triggered defined in routes.rb or Rails will not know how to call that action.

Example:

<%= link_to('Refresh', another_event_path, :remote => true) %>

Upvotes: 1

Related Questions