gpt4 book ai didi

ruby-on-rails - ActionController::ParameterMissing(缺少参数或值为空:电影):

转载 作者:行者123 更新时间:2023-12-04 00:08:45 28 4
gpt4 key购买 nike

因此,当我尝试访问我的应用程序上的电影页面时出现以下错误:

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'

请参阅下面的我的电影 Controller 代码

film_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

这可能是什么?我一直试图弄清楚它,但也许一组新的眼睛会发现它相当简单。

干杯!

编辑

这是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
<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

作为引用,这里是如何定义允许的参数在工作时的:
 def permitted_params

{:film => params.fetch(:film, {}).permit(
:name, :sort_name, :description, :short_description, :meta_data,
:poster, :amazon_link, :active, :trackable)}

end

最佳答案

我在使用Angular JS表单向后端Rails 4发送数据时也遇到了这个问题。当我在angular js表单中没有填写任何内容时,错误会显示ActionController::ParameterMissing (param is missing or the value is empty: .

我通过添加 params.fetch(:film, {}) 来修复它强参数为:

params.fetch(:film, {}).permit(:name, :sort_name, :description, :short_description, :meta_data,
:poster, :amazon_link, :active, :trackable, :country_ids => [])

我引用 code example to avoid ActionController::ParameterMissing (param is missing or the value is empty: film)

我希望这能帮到您。

关于ruby-on-rails - ActionController::ParameterMissing(缺少参数或值为空:电影):,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24944871/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com