ruby on rails - Add id to url wont work -
i have 2 model less views.
an index view:
<% @icd1.each |f| %> <%= link_to "#{f.von} #{f.bis} #{f.bezeichnung}", icd_show_path(f) %> </p> <% end %>
and show view:
<% @icd1.each |f| %> <%= link_to "#{f.von} #{f.bis} #{f.bezeichnung}", icd_show_path(f) %> </p> <% f.icd2.each |s| %> <%= s.von %><%= s.bis %><%= s.bezeichnung %> </p> <% end %> <% end %>
my controller:
class icdcontroller < applicationcontroller def index @icd1 = icd1.all end def show @icd1 = icd1.find(params[:id]) end end
but somehow link in index view, wont work:
<%= link_to "#{f.von} #{f.bis} #{f.bezeichnung}", icd_show_path(f) %>
when try access show page error:
couldn't find icd1 without id
and url shows
http://localhost:3000/icd/show
without id!
my routes:
get "icd/index" "icd/show"
1st: confusing naming: controller icd
, model icd1
..
2nd:
get "icd/show/:id", to: "icd#show", as: "icd_show"
or
get "icd/:id/show", to: "icd#show", as: "icd_show"
depends url want get. confusing.
but think need in url;
<%= link_to "#{f.von} #{f.bis} #{f.bezeichnung}", icd_show_path(f) %>
and routes:
get "icd/:id", to: "icd#show", as: "icd_show"
after next url available:
../icd/1
call action show
icd
controller
Comments
Post a Comment