【发布时间】:2023-04-02 11:25:01
【问题描述】:
当我提交表单时,“已发布”复选框的值未发布。
params3 = {"utf8"=>"✓", "authenticity_token"=>"i4SbblLJKIwba9yD30sDQCsir28/xdUxQZ90qYTNn0A=", "故事"=>{"姓名"=>"asdsaddsad", "post"=>"asdasdasdasd", "user_id"=>"13", "image_id"=>"1", "published"=>"1"}, "commit"=>"保存 故事”,“动作”=>“创建”,“控制器”=>“故事”}
def create
@story = Story.new(story_params)
respond_to do |format|
if @story.save
format.html { redirect_to @story, notice: 'Story was successfully created.' }
format.json { render action: 'show', status: :created, location: @story }
else
format.html { render action: 'new' }
format.json { render json: @story.errors, status: :unprocessable_entity }
end
end
end
<%= form_for @story do |f| %>
<%= f.text_field :name, placeholder: "Enter Title" %>
<%= f.text_area :post, placeholder: "Enter Story" %>
<br/>
<%= f.hidden_field :user_id, value: current_user.id %>
<%= f.hidden_field :image_id, value: @image.id %>
<%= f.label "Publish this" %>
<%= f.check_box :published %>
<%= f.submit "Save Story" %>
<% end %>
【问题讨论】:
-
显示你的表单,
published的数据类型是什么? -
对不起,忘记用花括号包起来
标签: ruby-on-rails ruby-on-rails-4