It turns out that I am building a form where a file can be selected. The problem is that when trying to build it it throws me the following error.
Routing Error
No route matches [POST] "/"
Next I will show the content of my controller and my routes file plus the content that makes up the form_tag.
If you need more info, feel free to ask me.
The error you show is because you are using
root_path
for your form submit, but you should useposts_path
for your form to submit tocreate
your controller actionPostsController
; example:For the helper
posts_path
to be available, you must update your routes (ie config/routes.rb ) by addingresources :posts
instead of `post '/posts', to: 'posts#create'.The above fixes the error, but your form will still not work since the content of the action
create
does not process the information you receive from the form (you are doing it innew
, which is wrong). Following Rails (and REST ) standards,new
it only responds with the verbGET
, while itcreate
responds toPOST
. So adjust the controllerPostsController
to reflect the above; for instance:It's important to note that the code you currently have in
create
won't work because itpost_params
doesn't contain the form information, but it will work if you wrap that method (and assuming you've set up your modelPost
properly); in fact that code is closer to what you should put in your application which, respecting the code of your form, could be something like this 1 :1 The form is assumed to be in the file new.html.erb , which would be correct by Rails standards.