Reputation: 1
I built my Rails Application an tried to include multi paperclip attachments. When I click the submit button at /collection/new It gives me the Error: No route matches [POST] "/collection/new" Here is My Code
new.html.erb
<%= form_for @collection, url: new_collection_path, :html => { multipart: true } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
</br>
<%= f.label :beschreibung %>
<%= f.text_field :description %>
</br>
<%= file_field_tag "images[]", type: :file, multiple: true %>
<%= f.submit %>
<% end %>
collection_controller.rb
class CollectionController < ApplicationController
def index
end
def new
@collection = Collection.new
end
def create
@collection = Collection.new(collection_params)
if @collection.save
if params[:images]
params[:images].each { |image|
@collection.pictures.create(image: image)
}
end
redirect_to @collection
else
render action "new"
end
end
def show
@collection = Collection.find(params[:id])
end
private
def collection_params
params.require(:collection).permit(:name, :description, :photos)
end
end
routes.rb
Rails.application.routes.draw do
root 'page#index'
resources :collection
end
And finally my routes
Prefix Verb URI Pattern Controller#Action
root GET / page#index
collection_index GET /collection(.:format) collection#index
POST /collection(.:format) collection#create
new_collection GET /collection/new(.:format) collection#new
edit_collection GET /collection/:id/edit(.:format) collection#edit
collection GET /collection/:id(.:format) collection#show
PATCH /collection/:id(.:format) collection#update
PUT /collection/:id(.:format) collection#update
DELETE /collection/:id(.:format) collection#destroy
Upvotes: 0
Views: 113
Reputation: 2775
You are suppose to post data to a "create" action, not a "new" action, "new" action usually returns the form for creating records. So, change the line:
<%= form_for :@collection, url: new_collection_path, :html => { multipart: true } do |f| %>
to:
<%= form_for @collection,:html => { multipart: true } do |f| %>
should works.
Upvotes: 1