ruby on rails - No route matches {:action=>"edit", :controller=>"comments", :id=>nil, :ribbit_id=>"18"} missing required keys: [:id] -
here's routes file:
resources :ribbits resources :comments end
here's comments_controller.rb edit action:
def edit @ribbit = ribbit.find(params[:ribbit_id]) @comment = @ribbit.comments.find(params[:id]) redirect_to @user unless @user == current_user end
and that's view:
<% @ribbit.comments.each |comment| %> <div class="comment"> <% comment_user = comment.user%> <img src="<%= comment_user.avatar_url unless comment_user.blank?%>"> <%= comment.user.name if comment.user %> <p> <%= comment.body if comment %> </p> <%= link_to "edit", edit_ribbit_comment_path(@ribbit, comment) %> </div> <% end %>
i getting error:
no route matches {:action=>"edit", :controller=>"comments", :id=>nil, :ribbit_id=>"18"} missing required keys: [:id]
would grateful help!
issue in rabbit controller action.
in show
action creating new comment
rabit
newly created comment not saved in database , not have id yet. in view error occurs there not id comment.
i don't know why creating comment if need should have check edit
link create link if record created. because make no sense edit record not created yet.
so work
<%= link_to "edit", edit_ribbit_comment_path(@ribbit, comment) unless comment.new_record?%>
Comments
Post a Comment