当我点击它时,我的form_for上的提交按钮没有做任何事情。我在控制台中确实有一条错误消息,上面写着“未经许可的参数:: photo_cache”但是当我看到这个时,我在控制器中的params中允许“photo_cache”,但是我的表单上的提交按钮仍然不起作用。
背景:我正在尝试创建一个具有以下参数的hairdressers:名称,描述,位置,照片和地址。
我的表格:
<%= simple_form_for(@hairdresser) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<%= f.input :name %>
<%= f.input :address %>
<%= f.input :location %>
<%= f.input :description %>
<%= f.button :submit, label: "Submit Form", class: "btn btn-primary" %>
class HairdressersController < ApplicationController
def index
@hairdressers = Hairdresser.all
end
def show
@hairdresser = Hairdresser.find(params[:id])
end
def new
@hairdresser = Hairdresser.new
end
def create
@hairdresser = Hairdresser.new(hairdresser_params)
# @hairdresser.save ? (redirect_to hairdresser_path(@hairdresser)) : (render 'new')
if @hairdresser.save
redirect_to hairdresser_path(@hairdresser)
else
render 'new'
end
end
def edit
@hairdresser = Hairdresser.find(params[:id])
end
def update
@hairdresser = Hairdresser.find(params[:id])
end
def destroy
@hairdresser = Hairdresser.find(params[:id])
end
end
private
def hairdresser_params
params.require(:hairdresser).permit(:name, :address, :photo, :location, :description, :photo_cache)
end
class Hairdresser < ApplicationRecord
belongs_to :user
validates :name, presence: true
validates :location, presence: true
validates :description, presence: true
validates :location, presence: true
mount_uploader :photo, PhotoUploader
end
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。