I have two views (for simplicity sake), one called Events, one called Friends. Their index pages list all of them. When you click one of the Friends in the friends index page, a jQuery function executes, allowing you to see their info.
My question is how (or if) I can use link_to in the Events page to link to the friends page, and then execute the correct jQuery function after to open that friend’s info.
So far it would be something like
= link_to "Edit Friend", 'friends'
I just need to know how or if I can execute a jQuery function after that page has been loaded.
You could use the URL hash (#) like this:
Where 5 is the id of the friend you want to show.
Then with javascript pick up the hash using
to show the selected friend
See here for an example: jsfiddle example,
see here for the source: jsfiddle source
Alternatively you can also route
/friends/:idto"friends#index"and use the:idparameter to display the selected friend