Ruby on rails 线路模块未定义方法的轨道形式_
我对示波器有问题。 我已经定义了Ruby on rails 线路模块未定义方法的轨道形式_,ruby-on-rails,ruby,Ruby On Rails,Ruby,我对示波器有问题。 我已经定义了 # routes.rb resources :asientos, module:'asientos' # app/models/asientos/asiento.rb module Asientos class Asiento < ActiveRecord:Base end end # app/controllers/asientos/asientos_controller.rb module Asientos class Asiento
# routes.rb
resources :asientos, module:'asientos'
# app/models/asientos/asiento.rb
module Asientos
class Asiento < ActiveRecord:Base
end
end
# app/controllers/asientos/asientos_controller.rb
module Asientos
class AsientosController < ApplicationController
def new
@asiento = Asientos::Asiento.new
end
end
end
# app/views/asientos/asientos/new
<%= form_for(@asiento) do |f| %>
...
现在每当窗体尝试渲染时,我都会
undefined method `asientos_asiento_index_path' for #<#<Class:0x000000065b3b40>:0x00000006ba5f30>
但它仍然需要一个亚洲索引路径。。。“undefined method`asientos\u index\u path'”您需要以\u的形式为帮助程序指定模块/命名空间,如下所示:
<% form_for [:asientos, @asiento] do |f| %>
您需要为helper指定形式为_的模块/命名空间,如下所示:
<% form_for [:asientos, @asiento] do |f| %>
好吧,在深入阅读了大量文章和代码之后,我找到了答案,正如一些帖子所指出的,这与词形变化有关。 我的应用程序有西班牙语的自定义屈折变化,其中屈折变化如下所示:
Usuario -> Usuarios
Asiento -> Asientos
ItemAsiento -> ItemsAsiento
你会注意到它将第一个单词改为复数。话虽如此,从rails/activemodel/lib/active_model/naming.rb中提取的rails源代码中的以下代码片段显示了发生的事情的内部结构
def initialize(klass, namespace = nil, name = nil)
@name = name || klass.name
raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if @name.blank?
@unnamespaced = @name.sub(/^#{namespace.name}::/, "") if namespace
@klass = klass
@singular = _singularize(@name)
@plural = ActiveSupport::Inflector.pluralize(@singular)
@element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(@name))
@human = ActiveSupport::Inflector.humanize(@element)
@collection = ActiveSupport::Inflector.tableize(@name)
@param_key = (namespace ? _singularize(@unnamespaced) : @singular)
@i18n_key = @name.underscore.to_sym
@route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
@singular_route_key = ActiveSupport::Inflector.singularize(@route_key)
@route_key << "_index" if @plural == @singular
end
def初始化(klass,namespace=nil,name=nil)
@name=name | | klass.name
引发ArgumentError,“类名不能为空。当给定匿名类时,您需要提供一个名称参数”if@name.blank?
@unnamespaced=@name.sub(/^#{namespace.name}::/,“”)如果是命名空间
@克拉斯
@单数=_单数(@name)
@复数=ActiveSupport::拐点。复数(@单数)
@element=ActiveSupport::拐点。下划线(ActiveSupport::拐点。解调(@name))
@human=ActiveSupport::influctor.humanize(@element)
@collection=ActiveSupport::Inflector.tableze(@name)
@param_key=(名称空间?_singularize(@unnamespaced):@singular)
@i18n_key=@name.下划线.to_sym
@route_key=(名称空间?ActiveSupport::influctor.pluralize(@param_key):@plural.dup)
@singular_route_key=ActiveSupport::拐点。singularize(@route_key)
@route_key好吧,在深入阅读了大量文章和代码之后,我找到了答案,正如一些帖子指出的那样,答案与词形变化有关。
我的应用程序有西班牙语的自定义屈折变化,其中屈折变化如下所示:
Usuario -> Usuarios
Asiento -> Asientos
ItemAsiento -> ItemsAsiento
你会注意到它将第一个单词改为复数。话虽如此,从rails/activemodel/lib/active_model/naming.rb中提取的rails源代码中的以下代码片段显示了发生的事情的内部结构
def initialize(klass, namespace = nil, name = nil)
@name = name || klass.name
raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if @name.blank?
@unnamespaced = @name.sub(/^#{namespace.name}::/, "") if namespace
@klass = klass
@singular = _singularize(@name)
@plural = ActiveSupport::Inflector.pluralize(@singular)
@element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(@name))
@human = ActiveSupport::Inflector.humanize(@element)
@collection = ActiveSupport::Inflector.tableize(@name)
@param_key = (namespace ? _singularize(@unnamespaced) : @singular)
@i18n_key = @name.underscore.to_sym
@route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
@singular_route_key = ActiveSupport::Inflector.singularize(@route_key)
@route_key << "_index" if @plural == @singular
end
def初始化(klass,namespace=nil,name=nil)
@name=name | | klass.name
引发ArgumentError,“类名不能为空。当给定匿名类时,您需要提供一个名称参数”if@name.blank?
@unnamespaced=@name.sub(/^#{namespace.name}::/,“”)如果是命名空间
@克拉斯
@单数=_单数(@name)
@复数=ActiveSupport::拐点。复数(@单数)
@element=ActiveSupport::拐点。下划线(ActiveSupport::拐点。解调(@name))
@human=ActiveSupport::influctor.humanize(@element)
@collection=ActiveSupport::Inflector.tableze(@name)
@param_key=(名称空间?_singularize(@unnamespaced):@singular)
@i18n_key=@name.下划线.to_sym
@route_key=(名称空间?ActiveSupport::influctor.pluralize(@param_key):@plural.dup)
@singular_route_key=ActiveSupport::拐点。singularize(@route_key)
@route_key能否添加@asiento
的初始化?当然,添加了!:)提前感谢。在呈现表单的视图中是否有其他按钮或链接?如果是,您可以添加与这些相关的代码吗?不,没有“真正的”按钮或链接,都是表示按钮的语义ui div,并单击javascript附加的事件以提交包含表单。以防万一,为了相同的结果,我删除了表单中的所有代码。您可以添加@asiento
的初始化吗?当然,添加了!:)提前感谢。在呈现表单的视图中是否有其他按钮或链接?如果是,您可以添加与这些相关的代码吗?不,没有“真正的”按钮或链接,都是表示按钮的语义ui div,并单击javascript附加的事件以提交包含表单。以防万一,我剥离了表单中的所有代码,得到了相同的结果。通过添加它,它进一步嵌套了名称空间输出未定义方法
asiento_asiento_asiento_index_path',通过添加它,它进一步嵌套了名称空间输出未定义的方法
asiento\u asiento\u asiento\u index\u path',我真的认为你的问题是另一个问题,看看这个,routes with scope module,不要contemple forform_with
,也可能是form_for
我也有同样的问题,所有问题都是英文的。仍然在寻找一个不是monkey Patch的解决方案我真的认为你的问题是另一个问题,看看这个,使用scope模块路由,不要用
来比较表单,很可能是表单的
我也有同样的问题,所有的问题都是英文的。仍然在寻找一个不是猴子补丁的解决方案