我有一个包含两个字段和 :remote => true 的简单表单。
我的控制器如下所示:
def create
@roadmap_item = RoadmapItem.new(params[:roadmap_item])
respond_to do |format|
if @roadmap_item.save
format.html { redirect_to @roadmap_item, notice: 'Roadmap item was successfully created.' }
format.json { render json: @roadmap_item, status: :created, location: @roadmap_item }
format.js { render js: @roadmap_item, status: :created, location: @roadmap_item, :layout => !request.xhr? }
else
format.html { render action: "new" }
format.json { render json: @roadmap_item.errors, status: :unprocessable_entity }
format.js { render js: @roadmap_item.errors, status: :unprocessable_entity }
end
end
结尾
我的“create.js.erb”文件是空的
如果我删除 format.js 行,对象会按预期创建。如果我保持原样,我会收到错误消息:"undefined method 'bytesize' for #<RoadmapItem:0x4061d30>"
我在 Windows 7 上使用 rails 3.2.8。
关于我做错了什么的任何想法?
堆栈跟踪:
[2012-11-08 23:08:31] ERROR NoMethodError: undefined method `bytesize' for #<RoadmapItem:0x4061d30>
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activemodel-3.2.8/lib/active_model/attribute_methods.rb:407:in `method_missing'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/attribute_methods.rb:149:in `method_missing'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/utils.rb:281:in `bytesize'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:24:in `block in call'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/query_cache.rb:46:in `each'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/query_cache.rb:46:in `each'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:454:in `each'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/body_proxy.rb:27:in `method_missing'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/body_proxy.rb:26:in `method_missing'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:24:in `call'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/rack/log_tailer.rb:17:in`call'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/devtools/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'