Reputation: 3
So at the moment I am following a Tutorial for a Photoblog for Ruby on Rails (my version is 5.0.1)
And right now I have a constant routing error
My routes.rb
looks as following, generated by Rails
Rails.application.routes.draw do
get 'posts/new'
get 'posts/create'
end
When I execute rake routes
I get this
Prefix Verb URI Pattern Controller#Action
posts_new GET /posts/new(.:format) posts#new
posts_create GET /posts/create(.:format) posts#create
What makes me curious is, that when I access /posts/create
manually, it is no problem at all like it should be.
But in /posts/new
I fill out a Form which will be redirected and here is where the error occurs
<%= form_tag({:action => :create}, :multipart => true) %>
<fields to be filled in>
</form>
Anybody a clue?
My Routing Error looks like this:
No route matches [POST] "/posts/create"
Upvotes: 0
Views: 47
Reputation: 513
Yes, the above answers are right. The question can be closed. An alternative would be to add this to your routes.rb
resources :posts this will give you all the common rails routes for a scaffold resource.
Upvotes: 0
Reputation: 30071
A route is identified by an HTTP verb and a path. Your route is
get 'posts/create'
GET
posts/create
A form by default has a POST
method (the HTTP verb), so you should change your route from
get 'posts/create'
to
post 'posts/create'
Upvotes: 0
Reputation: 33542
No route matches [POST] "/posts/create"
Your route for create
should be of type post
Change
get 'posts/create'
to
post 'posts/create'
Upvotes: 2