我一直在寻找其他答案,我仍然得到这个错误与params失踪。我猜这是一个回形针问题,但通过搜索文档后,我找不到解决此问题的任何内容。失败/错误:click_button“添加电影”ActionController :: ParameterMissing:参数丢失或值为空:电影
我的特色规格
scenario "An Admin creates a new movie" do
visit "/"
click_link "Add New Movie"```
fill_in "Title", with: "Creating first movie"
fill_in "Synopsis", with: "Lorem Ipsum"
fill_in "Year Released", with: "Date"
click_button "Add Movie"
expect(page).to have_content("Movie has been created")
expect(page.current_path).to eq(root_path)
expect(page).to have_content("Created by: #{@kyle.email}")```
end
我的电影模型
class Movie < ApplicationRecord
has_many :comments
belongs_to :admin
validates :title, presence: true
validates :synopsis, presence: true
validates :year_released, presence: true
has_attached_file :photo, styles: { medium: "300x200>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_file_name:照片,匹配:[?/ PNG \ Z /,/ JPE克\ Z /]```
我的控制器
def update
if @movie.update(movie_params)
flash[:success] = "Movie has been updated"
redirect_to @movie
else
flash.now[:danger] = "Movie has not been updated"
render :edit
end
end
private
def movie_params
params.require(:movie).permit(:title, :synopsis, :year_released, :photo)
end
我_form.html.erb
<div class="form-group">
<div class='control-label col-md-3'>
<%= f.label :photo %>
</div>
<div class='col-md-10'>
<%= f.file_field :photo, class: "btn btn-primary btn-sl pull-left" %>
</div>
<div class='form-group'>
<div class='col-md-offset-1 col-md-11'>
<%= f.submit "Add Movie", class: "btn btn-primary btn-lg pull-right" %>
</div>
错误
Failure/Error: click_button "Add Movie"
ActionController::ParameterMissing:
param is missing or the value is empty: movie```
我Github如果neccessary。
如何是你的form_for像 – uzaif
'''<%=的form_for(@movie)%> <%= f.label:标题%> <%= f.text_field:标题,类:“形式控制',占位符:'电影标题',自动对焦:true%> <%= f.label:synopsis%> <%= f.text_area:synopsis,rows:10,class:'form-control',占位符: '简介'%> <%= f.label:photo%> <%= f.file_field:photo,class:“btn btn-primary btn-sl pull-left”%>''' – kyle
更新时发生错误电影? – uzaif