Я пытаюсь загрузить фотографию, но после того, как я нажму кнопку загрузки, я получаю эту ошибку. Я новичок в rails 4, поэтому я не уверен, что мне не хватает.соответствует POST route rails 4
Моя логика - это когда я нажимаю кнопку отправки. Это вызовет действие create
для запуска и создания объекта IncomePicture
и сохранит его в моей базе данных.
No route matches [POST] "/income_pictures/new"
Маршруты:
root_path GET / static_pages#home
income_pictures_path GET /income_pictures(.:format) income_pictures#index
POST /income_pictures(.:format) income_pictures#create
new_income_picture_path GET /income_pictures/new(.:format) income_pictures#new
edit_income_picture_path GET /income_pictures/:id/edit(.:format) income_pictures#edit
income_picture_path GET /income_pictures/:id(.:format) income_pictures#show
PATCH /income_pictures/:id(.:format) income_pictures#update
PUT /income_pictures/:id(.:format) income_pictures#update
DELETE /income_pictures/:id(.:format) income_pictures#destroy
Контроллер:
class IncomePicturesController < ApplicationController
def new
@income_picture = IncomePicture.new
end
def create
@income_picture = IncomePicture.new(IncomePicture_params)
if @income_picture.save
flash[:notice] = "Income picture successfully uploaded"
redirect_to @income_picture
end
end
def show
@income_picture = IncomePicture.find(params[:id])
end
def index
@income_picture = IncomePicture.all
end
private
def IncomePicture_params
params.require(:income_picture).permit(:image, :name)
end
end
Вид:
<%= form_for :income_picture, :html => { :multipart => true } do |f| %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :image %>
<%= f.file_field :image %>
</p>
<p><%= f.submit %></p>
<% end %>
Вам необходимо ввести строчный код в свой метод IncomPicture_params. Ruby чувствителен к регистру, а метод рельсов для записи метода является строчным. Начиная с прописной буквы указывает константу. – ABMagil