I am following the example of SO # 9945620, Making a table row into a link in Rails The params being sent to the controller are {"controller"=>"cpe_events", "action"=>"cpe_course_description_live", "format"=>"15"}
I assume the format
is automatically being generated by rails. I don't, however, understand why it's adopting the row / record's id
and why the cpe_events params
or id
aren't being passed. Full code below the following notes.
Here's the data-link that's throwing the error: <tr data-link="<%= cpe_course_description_live_path(cpe_event) %>" >
That format is used in the referenced example. The link in the network section of my console reads cpe_course_description_live_path.15
However, the controller, @cpe_event = CpeEvent.find(params[:id])
, can't read the id
If I change it to: <tr data-link="<%= cpe_course_description_live_path(cpe_event, :format => 'html') %>" >
it correctly sends the format. The params are now {"controller"=>"cpe_events", "action"=>"cpe_course_description_live", "format"=>"html"}
and the network section of the console reads cpe_course_description_live_path.html
Bottom-line: Not passing the params or id to the controller.
Here's the view / table code:
<% @cpe_events.each do |cpe_event| %>
<tr data-link="<%= cpe_course_description_live_path(cpe_event, :format => 'html') %>" >
<td><%= cpe_event.id %></td>
.....
Here's the jQuery:
$(document).ready(function() {
$("tr").click(function() {
window.location = $(this).data("link");
})
})
Here's the controller:
def cpe_course_description_live
@cpe_event = CpeEvent.find(params[:id])
@user = current_user
redirect_to cpe_course_description_live_path(cpe_event)
end
Any help pointing me in the right direction would be appreciated. Thanks
Aucun commentaire:
Enregistrer un commentaire