ruby - Empty item at end of .each loop because of rails cycle method -
i have list should show activities inside category, , sort of works last element displayed strange. there 4 activities in db particular category , @ end of list i'm getting item /categories/1/activities
%table.catlist - @category.activities.each |activity| %tr{:class => cycle('one','two')} %td= link_to activity.name, [@category, activity] %td
i tried:
link_to activity.name, category_activity_path(:category_id => @category.id, :id => activity.id)
but that's not working @ all, , giving me error:
no route matches {:category_id=>1, :action=>"show", :controller=>"activities", :id=>nil}
the routes nested this:
resources :categories resources :activities resources :records end end
it's showing right, closes list strange element activity path, without id.
edit
i think happening because of cycle
method supposed switch between css classes. ideas how empty row can avoided?
you building new activity in controller included in list of activities @category
. if have following code in controller,
@activity = @category.activities.build
try changing to
@activity = activity.new category_id: @category.id
or add check in view show persisted activities.
- @category.activities.each |activity| - next if activity.new_record? %tr{:class => cycle('one','two')} %td= link_to activity.name, [@category, activity] %td
Comments
Post a Comment