jquery - link from table row to new view generating :format => id of clicked row Why? Rails -
i following example of # 9945620, making table row link in rails params being sent controller {"controller"=>"cpe_events", "action"=>"cpe_course_description_live", "format"=>"15"} assume format automatically being generated rails. don't, however, understand why it's adopting row / record's id , why cpe_events params or id aren't being passed.
edit: should note table rendered using bootstrap, class="span12 table table-hover table-striped table-bordered", since it's written in jquery.
full code below following notes.
here's data-link that's throwing error: <tr data-link="<%= cpe_course_description_live_path(cpe_event) %>" > format used in referenced example. link in network section of console reads cpe_course_description_live_path.15 however, controller, @cpe_event = cpeevent.find(params[:id]), can't read id
if change to: <tr data-link="<%= cpe_course_description_live_path(cpe_event, :format => 'html') %>" > correctly sends format. params {"controller"=>"cpe_events", "action"=>"cpe_course_description_live", "format"=>"html"} , network section of console reads cpe_course_description_live_path.html
bottom-line: not passing params or id controller.
here's view / table code:
<% @cpe_events.each |cpe_event| %> <tr data-link="<%= cpe_course_description_live_path(cpe_event, :format => 'html') %>" > <td><%= cpe_event.id %></td> ..... here's jquery:
$(document).ready(function() { $("tr").click(function() { window.location = $(this).data("link"); }) }) here's 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 pointing me in right direction appreciated. thanks
it bit hard tell sure, assume because of our routes. appears route using not member route, collection instead. why getting id after "." in url format type show up.
you should never need provide "html" format default. if post appropriate routes routes.rb file sure show problem
you can see url being produced cpe_course_description_live_path method running following console.
$ ~/code/my_app/rake routes | grep cpe_course_description_live edit: after research figured out there issue custom route. route should have looked this:
get '/cpe_events/:id/description_live(.:format)', to: 'cpe_events#cpe_course_description_live', as: 'cpe_course_description_live' this allowed :id added params hash in controller , accessed via params[:id]. difference between collection route , member route. in cause need id of member.
Comments
Post a Comment