Rails Url Generation Error -
i have 2 models section , newsitem
section.rb
class section < activerecord::base has_many :newsitems end
newsitem.rb
class newsitem < activerecord::base belongs_to :section end
in section controller have this:
class sectionscontroller < inheritedresources::base defaults collection_name: 'sections', instance_name: 'section' def newsitems @newsitem = @section.newsitems end end
in routes.rb
resources :sections resources :newsitems
in view i'm this:
<% @newsitem.order('created_at desc').each |newsitem| %> <div class="newsitem-block"> <%= newsitem.created_at.strftime("%d.%m.%y") %> <h1><%= link_to newsitem.title, newsitem %></h1> </div> <% end %>
but rails show me error
no route matches {:type=>nil, :action=>"show", :controller=>"newsitems", :id=>nil, :format=>nil} missing required keys: [:id, :id]
rake routes:
newsitems /offices(/:type)/:id/newsitems(.:format) newsitems#index {:type=>nil} post /offices(/:type)/:id/newsitems(.:format) newsitems#create {:type=>nil} new_newsitem /offices(/:type)/:id/newsitems/new(.:format) newsitems#new {:type=>nil} edit_newsitem /offices(/:type)/:id/newsitems/:id/edit(.:format) newsitems#edit {:type=>nil} newsitem /offices(/:type)/:id/newsitems/:id(.:format) newsitems#show {:type=>nil} patch /offices(/:type)/:id/newsitems/:id(.:format) newsitems#update {:type=>nil} put /offices(/:type)/:id/newsitems/:id(.:format) newsitems#update {:type=>nil} delete /offices(/:type)/:id/newsitems/:id(.:format) newsitems#destroy {:type=>nil}
what's wrong?
try:
<h1><%= link_to newsitem.title, [newsitem] %></h1>
or
<h1><%= link_to newsitem.title, newsitem_path(newsitem) %></h1>
Comments
Post a Comment