Ruby on rails 回形针与嵌套属性问题
使用回形针上传文件。我有项目、附件和关联表。我已经拥有了可以上传文件的一切,但是当它进入项目控制器时,它会寻找一个方法Ruby on rails 回形针与嵌套属性问题,ruby-on-rails,ruby-on-rails-3,associations,paperclip,nested-attributes,Ruby On Rails,Ruby On Rails 3,Associations,Paperclip,Nested Attributes,使用回形针上传文件。我有项目、附件和关联表。我已经拥有了可以上传文件的一切,但是当它进入项目控制器时,它会寻找一个方法附件文件名,然而,我相信它应该是用户文件名,因为:用户文件是附件模型用于有附件语句的。以下是生产日志: Started POST "/projects" for 136.152.181.137 at Mon Mar 28 16:23:28 -0700 2011 Processing by ProjectsController#create as HTML Paramete
附件文件名
,然而,我相信它应该是用户文件名
,因为:用户文件
是附件模型用于有附件
语句的。以下是生产日志:
Started POST "/projects" for 136.152.181.137 at Mon Mar 28 16:23:28 -0700 2011
Processing by ProjectsController#create as HTML
Parameters: {"commit"=>"Create Project", "authenticity_token"=>"xh0Ld2RKyJ6EF9jLNl3D+r1m50lKv389NCIor3H4fag=", "utf8"=>"?~\~S", "project"=>{"name"=>"Upload Test", "icon_id"=>"1", "categories_attributes"=>{"0"=>{"name"=>"Category 1", "_destroy"=>"false"}}, "content"=>"skee", "description"=>"description", "attachments_attributes"=>{"0"=>{"name"=>"name", "user_file"=>#<ActionDispatch::Http::UploadedFile:0x2aaaaf6b0fd8 @tempfile=#<File:/tmp/RackMultipart20110328-18838-4wasuv-0>, @headers="Content-Disposition: form-data; name=\"project[attachments_attributes][0][user_file]\"; filename=\"resized_DSCF0229.JPG\"\r\nContent-Type: image/jpeg\r\n", @original_filename="resized_DSCF0229.JPG", @content_type="image/jpeg">}}}}
Completed in 6ms
NoMethodError (undefined method `attachment_file_name' for #<Attachment:0x2aaaaf6a0638>):
app/controllers/projects_controller.rb:48:in `create'
app/controllers/projects_controller.rb:47:in `create'
我认为问题在于附件模型:
class Attachment < ActiveRecord::Base
has_attached_file :user_file
validates_attachment_presence :attachment
如果这是生产日志,它在开发环境中不会给出同样的错误吗?
def create
@project = Project.new(params[:project])
respond_to do |format|
if @project.save
format.html { redirect_to(@project, :notice => 'Project was successfully created.') }
format.xml { render :xml => @project, :status => :created, :location => @project }
else
format.html { render :action => "new" }
format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
end
end
end
class Attachment < ActiveRecord::Base
has_attached_file :user_file
validates_attachment_presence :attachment
validates_attachment_presence :user_file