html - Rails: Form_for: No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id] -
i new ror , trying build simple blog, got stuck @ "adding post" function.
the following error message pops when load .../posts/new
:
no route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id]
here posts controller looks this:
class postscontroller < applicationcontroller def index end def new end def create render plain: params[:post].inspect end
end
here new.html.erb
looks this:
<h1>add post</h1> <%= form_for :post, url: posts_path |f| %> <p> <%= f.label :title %><br> <%= f.text_field :title %> </p> <p> <%= f.label :body %><br> <%= f.text_area :body %> </p> <p> <%= f.submit %> </p> <% end %>
i had set posts resource in routes. surprising thing is, on friend's laptop, code works.
i happy advice, , apologize silly question.
the form_for
helper looking resource object operate with, , you're giving symbol. suspect it's assuming that's action url instead, , translating (or trying to) symbol route.
using form_for
in new
action, pattern create new resource , feed form_for
helper:
def new @post = post.new end
<%= form_for @post, url: posts_path |f| %> ... <% end %>
Comments
Post a Comment