- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
对于这个错误,我在 SO 上浏览了很多问题,但不幸的是我没有找到正确的答案。
我已经使用 rails generate scaffold Avis 创建了
.Avis
类(在法语中,它采用 s
,无论它是单数还是复数。) --force-plural
因为它是 Formation
类的一部分,这里是 route.rb 文件(部分):
resources :formations do
resources :avis
end
这是 Avis
Controller :
class AvisController < ApplicationController
before_action :set_avi, only: [:show, :edit, :update, :destroy]
before_action :set_formation
#On indique que les tests sont fait sur l'autorisation des utilisateurs
load_and_authorize_resource :formation
# gestion du layout
layout :sections_layout
@layout = 'back'
respond_to :html
def sections_layout
@layout
end
def index
@avis = Avis.where(:formations_id => Formation.find_by(:id => formation_params))
respond_with(@avis)
end
def show
respond_with(@avi)
end
def new
@avi = Avis.new
respond_with(@formation, @avi)
end
def edit
end
def create
@avi = Avis.new(avis_params)
@avi.save
respond_with(@avi)
end
def update
@avi.update(avis_params)
respond_with(@avi)
end
def destroy
@avi.destroy
respond_with(@avi)
end
private
def set_avi
@avi = Avis.find(params[:id])
end
def avis_params
params[:avi]
end
def formation_params
params.require(:formation_id)
end
def set_formation
@formation = Formation.find_by(:id => params[:formation_id])
if @formation == nil
redirect_to forbidden_path :status => 403
end
end
end
当我尝试创建一个新的 Avis
时,我得到了这个错误:
ActionView::Template::Error (undefined method `avis_index_path' for #<#<Class:0x007ffa6052aa78>:0x007ffa60528b88>):
1: <% puts @avi%>
2:
3: <%= form_for(@avi) do |f| %>
4: <% if @avi.errors.any? %>
5: <div id="error_explanation">
6: <h2><%= pluralize(@avi.errors.count, "error") %> prohibited this avi from being saved:</h2>
app/views/avis/_form.html.erb:3:in `_app_views_avis__form_html_erb__481767065103572634_70356711120220'
app/views/avis/new.html.erb:3:in `_app_views_avis_new_html_erb___1382100742020377330_70356626529020'
app/controllers/avis_controller.rb:29:in `new'
我该如何解决这个问题?
最佳答案
Avi
是 Formations
的嵌套资源,您的 form_for 应该看起来像这样 form_for(@formation, @avi)
,它将使用正确的 formation_avis_path。
有关嵌套资源的更多信息,请查看 Rails Routing from the Outside In
关于ruby-on-rails - 将 form_for 与复数类名一起使用时,rails 4 未定义方法 `_index_path',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30306258/
是 {:action => 'update', :id => @product.id})) do |f| %> ... 和 {:action => 'update', :id => @pro
我实现了一个表单文本字段字符计数器,它可以在 jsfiddle 中工作,但不能在应用程序中工作。它会出现,但不会像在 jsfiddle 中那样实时计数。当我重新加载页面时,它将计算文本字段中的当前字符
我正在尝试创建一个只有一个文本字段和一个隐藏字段的表单,我将在将数据传递到 HTTP API 时使用该字段,因此我没有与之关联的模型,并且通过扩展,没有变更集。 是否可以做到这一点并使用 form_f
我的表单如下所示: ~~~form stuff~~~ { disable_with: "Processing" }, :class => "btn btn-info
我需要将表单提交到外部 URL,所以我有这个: form_for(@task, :url => "https://www.external.com/Submit") do |f|) @ass
我有两个模型: 品牌 has_many :products 产品 belongs_to :brand 在我看来 (show_brand.html.erb),我使用 @brand.name ... 显示
我在财务模块中有以下模型: class Finance::BillRec :destroy ... end class Finance::BillRecOff ... 路线.rb nam
我写了以下代码:- 翻译成 我的 routes.rb 文件包含以下代码:- root 'static_pages#home' get 'contact'=>'static_pages#conta
我正在试验嵌套资源: 我的路线: resources :conversations do resources :replies do resources :comments
我的项目是这样组织的:用户是主要资源,每个用户都有一个配置文件,每个配置文件都有一个位置,如下所示: resources :users do resource :profile, :c
我有一个表单,提交后会运行 sidekiq 工作程序。目前,如果您在空表单上单击“提交”,它会尝试运行工作程序。我想要的是它提醒用户在提交之前需要填写这些字段。 我尝试将 :required => t
我有一个关于 form_for 和嵌套资源的两部分问题。假设我正在编写一个博客引擎,并且我想将评论与文章相关联。我定义了一个嵌套资源,如下所示: map.resources :articles do
我想要一个 form_for @user,但要发布到用户 Controller 中的自定义操作。 我该怎么做? 最佳答案 form_for @user, :url => url_for(:contro
我有一个 Rails form_for html 元素。该表单有一个调用 JavaScript 函数的 onsubmit 属性。 onsubmit 工作正常,但是当我添加额外的参数时,js 函数不再受
我试图在提交之前验证我的 form_for 中所有必需的字段是否已完成,并且已完成 95%,但在检查和发出警报之前它仍然会提交。 这是表单的开头: {:id => "new_listing", :o
如果有更好的方式来表达这个问题,或者有更好的方式来做到这一点,请告诉我。 我想使用模态的 form_for 更新一些模型。用户单击“编辑”和带有字段的模式弹出窗口,然后可以单击提交或取消。我可以做到这
我正在尝试在 Rails 中使用客户端验证 Gem。我的表单一直在查找,直到将 `:validate => true"添加到我的 form_for 中。然后我收到一条错误消息,告诉我我编写它的方式是错
我在父 View 中有一个 div,它呈现 show 部分。在这个 show 部分中,我有一个按钮应该更改父部分的部分以呈现“form”部分以编辑对象,但我一直被卡住,因为似乎“form”部分的 fo
我正在使用 form_for 创建一个具有 1 个输入字段和 1 个按钮的表单。我希望提交按钮位于输入字段旁边而不是下方。 相关代码为: .input{border: 1px solid #66666
对于我下面的表格,如何防止表格跳到下一行?我查看了 Bootstrap 类“form-inline”,但似乎没有用,因为它禁用了我的表单。 Hello World! 这导致:
我是一名优秀的程序员,十分优秀!