我有一個錯誤:不能轉換成字符串整數上更新
TypeError in PrintsController#update
can't convert String into Integer
我使用的格式代碼是:
<%= form_for @print do |f| %>
....
....
<%= f.fields_for :blackwhites_attributes do |blackwhite| %>
<%= blackwhite.select :newpages , options_for_select((1..(@print.number_of_images_entry)).to_a), {}, :multiple => true, :size => @print.number_of_images_entry %>
<% end %>
,而在我的development.log,我看到「newpages」選擇字段中有一個空值。
> Parameters: {"utf8"=>"✓", "authenticity_token"=>"xAs20vFEt3vEBOhFugOyR0nWIgkoMJ0d4JPbl5E5VQ4=",
> "print"=>{"quantity"=>"1", "blackwhites_attributes"=>{"newpages"=>["",
> "2", "3"]}, "comment"=>""}, "commit"=>"Update Print", "id"=>"5"}
> User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1000 LIMIT 1
> Print Load (0.3ms) SELECT `prints`.* FROM `prints` WHERE `prints`.`id` = ? LIMIT 1 [["id", "5"]]
> SQL (0.1ms) BEGIN
> (0.1ms) ROLLBACK
> Completed 500 Internal Server Error in 6ms
我blackwhite模型「連載」以及對數字的陣列存儲到數據庫:
class Blackwhite < ActiveRecord::Base
attr_accessible :newpages, :print_id
serialize :newpages
belongs_to :print
end
但我發現問題將具有打印控制器更新未建形式和我有建立在Prints_controller
def update
@print = Print.find(params[:id])
@print.blackwhites.build
if @print.update_attributes(params[:print])
redirect_to @print, :flash => { :success => "Successfully updated your Print Order." }
else
render :action => 'edit'
end
end
打印型號:
class Print < ActiveRecord::Base
has_many :blackwhites
belongs_to :user
accepts_nested_attributes_for :blackwhites, :allow_destroy => true
attr_accessible :comment, :document, :document_file_name,
:document_file_size, :document_updated_at, :is_printing,
:is_processing_image, :user_id, :document_content_type,
:number_of_images_entry, :is_delivered, :quantity, :blackwhites_attributes
...
...
end
你可以發表代碼og打印模型 –
添加打印模型。 – muhammadn
你能發佈完整的堆棧跟蹤嗎? –