i have somes relations in my table like this
Model : Floors
has_many :photo
Model : Photo
belongs_to :floors
belongs_to :file_type
Model : file_type
has_many :photo
Photo are nested attributes with render inside floors form.
The problem is if i change the file type inside the form without any other change in the form, the new selected alements are not updated, and the update_attributes (in the WEBrick) console, the new selected are not updated.
Photo are a paperclip element with versioning. I don't want to update each time the file if i just want to change his file type related.
Thanks for your help.
EDIT : Has asked, my views.
# _form.html.erb
<% f.fields_for :floor_photo do |floor_photo| -%>
<%= render 'floor_photo_fields', :f => floor_photo %>
<% end -%>
<div>
<%= link_to_add_fields "Add Photo", f, :floor_photo %>
</div>
# _floor_photo_fields.html.erb
<div class="fields">
<%= f.label 'P开发者_Python百科hoto' %><br/>
<%= f.file_field :photo %>
<%= f.collection_select :file_type_id, FileType.all(:order => 'name'), :id, :name, {:prompt => 'Select'}%>
<%= link_to_remove_fields "remove", f %><br/>
<div style="margin-bottom:10px;"><%= f.object.photo_file_name %></div>
</div>
For now, if i click Add Photo, and set a file type to the photo, it's work, but when i edit a floors and want to change the file type, he don't want to take the new file_type_id and don't do any update sql statement. Like if i have nothing changed in my form.
And yes, sorry for my relations, it was a typo mistake, all are good in my models form.
# floor_photo.rb
class FloorPhoto < ActiveRecord::Base
versioned
belongs_to :floor
belongs_to :file_type
has_attached_file :photo, :keep_old_files => true, :url => "/system/buildings/photos/:id/:version/:basename.:extension",
:path => ":rails_root/public/system/buildings/photos/:id/:version/:basename.:extension"
Paperclip.interpolates :version do |attachment, style|
attachment.instance.version.to_s
end
end
# file_type.rb
class FileType < ActiveRecord::Base
has_many :floor_photos
end
I hope this help someone to help me.
Sorry, here is my controller
floors_controllers.rb
def edit
@floor = Floor.find(params[:id])
end
def update
@floor = Floor.find(params[:id])
if @floor.update_attributes(params[:floor])
redirect_to space_path(@floor)
else
render :action => 'edit'
end
end
The code doesn't look right:
Model : Floors
has_many :photo #should be :photos
Model : Photo
belongs_to :floors #should be :floor
belongs_to :file_type
Model : file_type
has_many :photo #should be :photos
精彩评论