Created
May 15, 2011 23:03
-
-
Save vladimir-vg/973651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.grid_fs_host = Mongoid.config.master.connection.host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.grid_fs_host = Mongoid.database.connection.primary_pool.host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Image | |
include Mongoid::Document | |
embedded_in :market_item | |
mount_uploader :attach, ImageUploader | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MarketItem | |
include Mongoid::Document | |
embeds_many :images, :stored_as => :array | |
# BUGFIX | |
# next code-line needed for fix bug array described here: | |
# http://tinyurl.com/6yntj3r | |
accepts_nested_attributes_for :images | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @market_item, :html => {:multipart => true} do |f| -%> | |
<%= f.fields_for :images do |builder| -%> | |
<%= builder.label :attach %> | |
<%= builder.file_field 'attach' %> | |
<% end -%> | |
<%= f.submit "Отправить" %> | |
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GET /market_items/new | |
# GET /market_items/new.xml | |
def new | |
@market_item = MarketItem.new | |
3.times { @market_item.images.build } | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @market_item } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# POST /market_items | |
# POST /market_items.xml | |
def create | |
@market_item = MarketItem.new(params[:market_item]) | |
respond_to do |format| | |
if @market_item.save | |
# BUGFIX | |
# Don't know why, but nested images does not saves automaticly | |
# bug a bit described here (at end): | |
# http://flux88.com/blog/using-carrierwave-with-mongoid/ | |
@market_item.images.each {|x| x.save!} | |
format.html { redirect_to(@market_item, | |
:notice => 'created.') } | |
format.xml { render :xml => @market_item, | |
:status => :created, | |
:location => @market_item } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @market_item.errors, | |
:status => :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment