ActionController::ParameterMissing(缺少参数或值为空:电影): [英] ActionController::ParameterMissing (param is missing or the value is empty: film):
问题描述
因此,当我尝试访问我的应用上的电影页面时出现以下错误:
So, I'm getting the following error when trying to visit the films page on my app:
ActionController::ParameterMissing (param is missing or the value is empty: film):
2014-07-24T22:04:44.622356+00:00 app[web.1]: app/controllers/saas_admin/films_controller.rb:54:in `permitted_params'
在下面查看我的电影控制器代码
See my films controller code below
films_controller.rb
class SaasAdmin::FilmsController < SaasAdminController
inherit_resources
belongs_to :studio, :finder => :find_by_id!, :param => :studio_id, :class_name => Studio
before_filter :set_sort_fields, :only => :edit
before_filter :build_collections, :only => [:new, :create, :edit, :update]
def create
create! { parent_path(parent.id) } # Redirect to studio in case studio_id is changed
end
def update
@film = Film.find_by_permalink(params[:id])
respond_to do |format|
if @film.update(permitted_params)
format.html { redirect_to saas_admin_studio_path(@film.studio), notice: 'Film was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @film.errors, status: :unprocessable_entity }
end
end
end
def index
redirect_to parent_path(parent.id)
end
def show
@clips = resource.clips.paginate(:page => params[:page], :per_page => 30, :order => 'clips.position')
end
protected
def resource
# @film ||= end_of_association_chain.find_by_permalink!(params[:id])
@film ||= end_of_association_chain.find_by_permalink!(params[:id])
end
def collection
@films ||= end_of_association_chain.paginate(:page => params[:page], :per_page => 30, :order => 'films.created_at')
end
def set_sort_fields
resource.sort_name = '' if resource.name == resource.sort_name
end
def build_collections
@studios ||= Studio.find(:all)
end
def permitted_params
params.require(:film).permit(:name, :sort_name, :description, :short_description, :meta_data,
:poster, :amazon_link, :active, :trackable, :country_ids => [])
end
end
这可能是什么?我一直试图弄清楚它,但也许一组新的眼睛会发现它相当简单.
What might this be? I've been trying to figure it out for a bit but perhaps a fresh set of eyes will find it's something rather simple.
干杯!
编辑
这是films/new.html.erb的查看代码
Here's the view code for films/new.html.erb
<h1><%= @page_title = "New #{resource_class}" %></h1>
<%= form_for resource, :url => collection_path, :html => { :multipart => true } do |f| -%>
<%= render :partial => "form", :locals => { :f => f } %>
<% end -%>
<% content_for :sidebar do %>
<%= render :partial => "saas_admin/shared/sidebar" %>
<% end %>
和电影/edit.html.erb
and films/edit.html.erb
<h1><%= @page_title = "Edit #{resource_class}" %></h1>
<%= form_for resource, :url => saas_admin_studio_film_path(parent, resource), :html => { :multipart => true } do |f| -%>
<%= render :partial => "form", :locals => { :f => f } %>
<% end -%>
<% content_for :sidebar do %>
<%= render :partial => "saas_admin/shared/sidebar" %>
<% end %>
编辑 2
这里参考的是在工作时如何定义允许的参数:
For reference here is how the permitted params was defined when it was working:
def permitted_params
{:film => params.fetch(:film, {}).permit(
:name, :sort_name, :description, :short_description, :meta_data,
:poster, :amazon_link, :active, :trackable)}
end
推荐答案
发生这种情况是因为您已通过 strong_params(在上面的 permited_params 代码中指定)在参数中指定 require 'film'.
This is happening because you have specified to require 'film' in your parameters through strong_params (specified above in your permitted_params code).
无论视图端在做什么(无论是链接还是表单/等),它都不会传递嵌套在电影"下的参数
Whatever the view side is doing (whether its a link or a form/etc.), its not passing its parameters nested under 'film'
例如)如果你在控制器动作中raise params.inspect
,你会看到没有film"节点.
eg.) if you were to raise params.inspect
in the controller action, you would see that there is no node for "film".
最有可能的问题是您在视图端的表单代码没有设置为正确嵌套这些参数,例如您是否使用了 form_tag
?
Most likely what is wrong is that the form code you have on the view side is not set to nest these parameters properly, are you using a form_tag
for example?
这篇关于ActionController::ParameterMissing(缺少参数或值为空:电影):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!