需要一些帮助。应用程序在 ruby 1.8.7 和 rails 3.0.11 下运行。将 Rails 版本更新到 3.1.11 后,在新文章页面上出现了一个非常奇怪的错误:http: //cl.ly/image/1o0P050d2q41
但是在控制器中我有:
class ArticlesController < ApplicationController
def new
@article = Article.new
end
和通常的 form_for @article 视图。奇怪的是,编辑操作工作得很好,就像在 Rails 更新之前一样。
有什么想法会导致问题以及如何解决?
编辑:文章.rb
require 'acts_as_list'
class Article < ActiveRecord::Base
attr_accessible :name, :body, :category_id, :preview, :status, :position, :publish_on_main
acts_as_commentable
acts_as_list
belongs_to :category, :counter_cache => true
belongs_to :user, :counter_cache => true
has_many :relative_articles, :dependent => :destroy
has_many :relatives, :through => :relative_articles
validates_presence_of :name, :body, :category_id, :preview
validates_length_of :name, :within => 10..100
validates_length_of :preview, :within => 100..2000
validates_length_of :body, :within => 500..50000
scope :published, where(:aasm_status => :publics)
scope :draft, where(:aasm_status=> [:draft, :deleted])
scope :deleted, where(:aasm_status => :deleted)
scope :not_deleted, where(:aasm_status => [:publics, :draft])
def relative_ids
self.relatives.published.map(&:id)
end
def to_param
"#{id}-#{name.parameterize}"
end
define_index do
indexes name
indexes preview
indexes body
has category_id
where "aasm_status = 'publics'"
set_property :delta => true
end
这就是控制台中显示的内容:
Started GET "/articles/new" for 127.0.0.1 at Sun May 26 18:47:43 +0400 2013
Processing by ArticlesController#new as HTML
Completed 500 Internal Server Error in 270ms
ArgumentError (wrong number of arguments (1 for 0)):
Rendered /Users/iriskin/.rvm/gems/ree-1.8.7-2012.02@mednadom/gems/actionpack-3.1.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
Rendered /Users/iriskin/.rvm/gems/ree-1.8.7-2012.02@mednadom/gems/actionpack-3.1.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms)
Rendered /Users/iriskin/.rvm/gems/ree-1.8.7-2012.02@mednadom/gems/actionpack-3.1.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (3.4ms)
编辑 2* new.html.erb:
<%= form_for @article do |f| %>
<%= render "shared/error_messages", :target => @article %>
<% if admin? %>
<p>
<%= f.label :user_id %>
<%= f.select :user_id, User.authors_and_admins.collect {|p| [ p.username, p.id ] } %>
</p>
<% end %>
<p>
<%= f.label :category_id %><%= mark_required(@article, :category_id) %><br/>
<%= f.select :category_id, Category.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true } %>
</p>
<p>
<%= f.label :name %><%= mark_required(@article, :name) %><br/>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :preview %><%= mark_required(@article, :preview) %><br/>
<%= f.text_area :preview, :size => "70x6" %>
</p>
<p>
<%= f.label :body %><%= mark_required(@article, :body) %><br/>
<%= f.text_area :body, :class => "mceEditor", :size => "100x20" %>
</p>
<% if admin? %>
<p>
<%= f.label :publish_on_main %>
<%= f.check_box :publish_on_main %>
</p>
<% end %>
<%= f.submit %>
<% end %>