ruby on rails - No route matches {:action=>"show", :controller=>"forum"} missing required keys: [:id] -
i'm trying route thredded /forum link on nav bar bug holding me back. not sure if installation issue or pathing one. thanks!
routes.rb
rails.application.routes.draw resources :links mount thredded::engine => '/forum' # creates about_path resources :forum devise_for :users root "pages#home" "about" => "pages#about" end
home page / _header.html.erb
<nav class="navbar navbar-static-top navbar-default" role="navigation"> <div class="container"> <!-- brand , toggle grouped better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <%= link_to "rowlund", root_path, class: "navbar-brand" %> <nav class="navbar navbar-default navbar-fixed-bottom"> <div class="container"> </div> </nav> </div> <!-- collect nav links, forms, , other content toggling --> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li><%= link_to "home", root_path %></li> <li><%= link_to "forum", forum_path%></li> <li><%= link_to "about", about_path %></li> <% if user_signed_in? %> <li><%= link_to "account settings", edit_user_registration_path %> </li> <li><%= link_to "log out", destroy_user_session_path, method: :delete %></li> <% else %> <li><%= link_to "log in", new_user_session_path %></li> <% end %> </ul> </li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container --> </nav>
if run rake routes
or rake routes | grep forum
, should find following route in list of routes.
forum /forums/:id(.:format) forums#show
the route /forums/:id
maps forums#show
, need pass in id
in url. eg:
forums_path(3) => /forums/3 forums_path(forum.find(1)) => /forums/1
in code, you're not passing id
forum_path
.that why you're getting error missing required keys: [:id]
since don't have particular forum
object map in navbar links, should better map link index
action. change following link
<li><%= link_to "forum", forum_path %></li>
to
<li><%= link_to "forum", forums_path %></li>
note forums_path
maps forums#index
Comments
Post a Comment