【发布时间】:2016-04-06 03:31:09
【问题描述】:
我有一个表单来编辑页面,但它告诉我它不是我从相关问题中知道的变量。看来,从这一行引发了一个错误:
<%= form_for @wiki, :url => giki_path(@wiki.name), :html => { :method => :put } do |f| %>
@wiki 似乎是一个实例,可以通过以下方式确认:
$ rails console
> @wiki
#<Gollum::Page:70026260995800 Home (markdown) @wiki="path/to/git/wiki/.git">
> @wiki.name
"/wiki/Home"
所以我不明白是什么导致了问题:
undefined method `model_name' for #<Gollum::Page:0x007f6084d2bdb0>
编辑:
在控制器中:
# giki_controller.rb
def edit
@wiki = Wiki.find(params[:id])
end
# the same method, worked fine
def show
@wiki = Wiki.find(params[:id])
end
在模型中:
# wiki.rb
class Wiki
include ActiveModel::AttributeMethods
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name, :raw_data, :formatted_data, :title, :path, :change_desc, :versions
# Gollum Init
WIKI = Gollum::Wiki.new(Settings.wiki_repo, :base_path => "/wiki")
# initialize
def initialize(attributes = {})
attributes.each do |key, value|
send("#{key}=", value)
end
end
# no database
def persisted?
false
end
def self.find(name)
WIKI.page(name) # find a page by name
end
记录器的第一行:
NoMethodError - undefined method `model_name' for #<Gollum::Page:0x007f607dfec4e8>:
actionpack (4.2.6) lib/action_controller/model_naming.rb:9:in `model_name_from_record_or_class'
actionview (4.2.6) lib/action_view/record_identifier.rb:47:in `dom_class'
完整回溯:我创建了一个gist。
【问题讨论】:
-
请提供实际的错误信息,未经编辑。
-
@toddmetheny 回溯太长。我使用了better_errors,其中唯一提示的消息是未定义的方法行。
-
那么你真的在你的应用程序中调用了一个名为
model_name的方法吗?如果是,请提供与该方法调用相关的代码。 -
@toddmetheny 我不这么认为。它隐含在回溯的某个地方。我会更新代码。
-
您的
edit操作在您的WikisController中是什么样的?
标签: ruby-on-rails