ruby-on-rails-3

Upload file to S3 using CarrierWave without a model, is it possible?

大憨熊 提交于 2019-12-30 02:13:09
问题 CarrierWave has amazing documentation, until you need to do it without a model! I have my uploader and fog settings set up, and they all work fine when using the mounted uploader on a model, but now I want to do it without a model. I have this: uploader = CsvUploader.new something = uploader.store!(File.read(file_path)) uploader.retrieve_from_store!(self.file_name) When I call .store! the code runs immediately which is weird since it should take a few seconds to upload the file? Then after I

Rails 3 automatic asset deployment to Amazon CloudFront?

血红的双手。 提交于 2019-12-30 02:09:09
问题 Is there a gem or method available in Rails 3.1 that can upload assets to amazon cloud front automatically and use those instead of serving locally hosted ones? I guess it's easy to upload compiled assets manually and then change the rails app config to use that asset host, but when an asset is modified, the uploads to cloud front would need to be done manually again. Any good ways out there for this? 回答1: Definitely check out asset_sync on github. Or our Heroku dev centre article on Using a

Rails 3 automatic asset deployment to Amazon CloudFront?

六眼飞鱼酱① 提交于 2019-12-30 02:08:00
问题 Is there a gem or method available in Rails 3.1 that can upload assets to amazon cloud front automatically and use those instead of serving locally hosted ones? I guess it's easy to upload compiled assets manually and then change the rails app config to use that asset host, but when an asset is modified, the uploads to cloud front would need to be done manually again. Any good ways out there for this? 回答1: Definitely check out asset_sync on github. Or our Heroku dev centre article on Using a

What needs to be configured for Heroku to handle templates based on CoffeeScript?

戏子无情 提交于 2019-12-30 01:58:04
问题 I have a create action that handles an AJAX request. On my development machine, a template named create.js.coffee is successfully processed to generate a javascript response. However, when I deploy to Heroku, the application complains that it can't find the template. ActionView::MissingTemplate (Missing template /expenses/create with {:handlers=>[:erb, :builder], :formats=>[:js, :html], :locale=>[:en, :en]}. Searched in: * "/app/app/views" * "/app" * "/" ): It's clear that the coffee handler

Rails3 - Caching in development mode with Rails.cache.fetch

别等时光非礼了梦想. 提交于 2019-12-30 01:52:26
问题 In development, the following (simplified) statement always logs a cache miss, in production it works as expected: @categories = Rails.cache.fetch("categories", :expires_in => 5.minutes) do Rails.logger.info "+++ Cache missed +++" Category.all end If I change config.cache_classes from false to true in config/development.rb, it works as well in development mode, however, this makes development rather painful. Is there any configuration setting that is like config.cache_classes = false except

What does the * (asterisk) symbol do near a function argument and how to use that in others scenarios?

风流意气都作罢 提交于 2019-12-30 01:51:29
问题 I am using Ruby on Rails 3 and I would like to know what means the presence of a * operator near a function argument and to understand its usages in others scenarios. Example scenario (this method was from the Ruby on Rails 3 framework): def find(*args) return to_a.find { |*block_args| yield(*block_args) } if block_given? options = args.extract_options! if options.present? apply_finder_options(options).find(*args) else case args.first when :first, :last, :all send(args.first) else find_with

Generating a short UUID string using uuidtools In Rails

你。 提交于 2019-12-30 01:51:07
问题 I have to generate a unique and random string which is to be stored in database. For doing this I have used the "uuidtools" gem. Then in my controller I have added the following line: require "uuidtools" and then in my controllers create method I have declared a 'temp' variable and generating a unique and random 'uuid' string like this: temp=UUIDTools::UUID.random_create which is creating a string like this one: f58b1019-77b0-4d44-a389-b402bb3e6d50 Now my problem is I have to make it short,

Rails 3 routing - passing params from routes.rb

梦想的初衷 提交于 2019-12-30 01:45:12
问题 In rails 2.3.5 you could do something like this inside the routes.rb file: map.root :controller => "pages", :action => "show", :id => 3 In rails 3 I haven't found any way to pass a specific parameter (like in rails 2.3.5 with :id => 3). I know I can handle it from the controller and have the same result (which I did), but I was wondering if there is a way to do the same thing in rails 3 from the routes.rb or has it changed because it is better practice for some reason? 回答1: Are you sure the

Why is Date.today - 6.months + 6.months != Date.today?

落花浮王杯 提交于 2019-12-30 01:37:05
问题 In Ruby, on Halloween: Date.today - 6.months + 6.months != Date.today Do we need to update Ruby's date implementation? Do other languages have the same issue? 回答1: This happens if you do it to any month that doesn't have 31 days (i.e. 3 months would work just fine, but 1 month, or 6, or 8 would all make this happen). If you do Date.today - 1.month , it looks like Rails sees that 9/31/2011 isn't a valid date, so it kicks it back an extra day to make it a valid date. However, when you go one

Customize error message with simple_form

陌路散爱 提交于 2019-12-30 01:34:12
问题 I'm using the simple_form gem. I want to customize the error message displayed when a user fails validations. How can I accomplish this? 回答1: You can easily change the default error message comes in the translation file, which is found in config/locales/simple_form.en.yml . In the specific initializer, config/initializers/simple_form.rb you can overrule the default options how the html is generated. Hope this helps. For completeness, I would like to add that formtastic is an easier choice to