How to build a remote_to link and pass a param
I have a model: ThreadParticipation
I want to build a link that send the ThreadParticipation.id and a param hide == true.
How can I build a link that does this?
ThreadParticipation Controller:
def hide
@record = ThreadParticipation.find开发者_运维百科(params[:id)
@record.hide == params[:hide]
@record.save
end
View:
<%= link_to "hide", '/thread/:id/thread_participations/:id/hide', :remote => true %>
Does that look right? How do I pass a param a long with the link_to (hide == true) ? Any ideas?
Thanks
You could try this
<%= link_to "hide", "/thread/#{thread_id}/thread_participations/#{id}/hide?hide=true", :remote => true %>
Or better still, define a route to get the /thread/:thread_id/thread_participation/:id part. Lets say the route is hide_thead_pariticipation_thread_path
<%= link_to "hide", hide_thread_participation_path(thread_id,:hide => true), :remote => true %>
Also your controller code seems to be using "@record.hide == params[:hide]". Maybe its just a = there?
精彩评论