ruby-on-rails-3

Rails 3 has_many changed?

可紊 提交于 2021-02-18 05:31:26
问题 I need to track changes (additions and deletes) of an association set up like this: has_many :listing_services has_many :services, through: :listing_services For normal attributes the easist way to do it is to check l.changes[attribute] in before_save or l.previous_changes[attribute] in after_save . The question is, what is the best way to do it for has_many attributes? 回答1: I didn't use changes method. But I'm sure that you always can use magic methods <attribute_name>_changed? and

Rails - only find records where has_many associated records are present

核能气质少年 提交于 2021-02-17 19:21:26
问题 I have a model with a has_many relation with another model like so: class Parent < ActiveRecord::Base has_many :children end class Child < ActiveRecord::Base belongs_to :parent end Since there are some parents that may not have children, I'd like to do a query that returns only the parents that DO have children. How would I go about something like this? Since I'm doing this on Rails 3, it would be helpful if this query were to not use the where.not. syntax. 回答1: Rails 4 Parent.includes(:child

How to crop image on upload with Rails, Carrierwave and Minimagick?

只谈情不闲聊 提交于 2021-02-17 16:58:47
问题 I have read: Undefined Method crop! Using Carrierwave with MiniMagick on rails 3.1.3 Carrierwave Cropping http://pastebin.com/ue4mVbC8 And so I tried: # encoding: utf-8 class ProjectPictureUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end version :thumb do process :cropper # process :crop process resize_to_fit: [200, 200] end def cropper manipulate! do |img| # if model.crop

Check if folder exist in s3 bucket

谁都会走 提交于 2021-02-16 13:16:12
问题 How can I check if some folder exists in my s3 bucket using Ruby on Rails? I’m using AWS:S3 official gem After initializing the global connection AWS::S3::Base.establish_connection!(:access_key_id => 'my_key_id', :secret_access_key => ‘my_secret’) I have bucket named: myfirstbucket With folder inside named: my_folder With file inside my_folder named: my_pic.jpg When I try to check if my_pic.jpg exist it work just fine s3object.exists? “/my_folder/my_pic.jpg” , “myfirstbucket” => True How can

wrong number of arguments (given 1, expected 0)

ぃ、小莉子 提交于 2021-02-11 14:51:21
问题 I want to upload photos to my website. After i selected the photos and click on "Add Photos" this error comes up. Any ideas how i can solve this? photos_controller.rb class PhotosController < ApplicationController def create @wall = Wall.find(params[:wall_id]) if params [:images] params[:images].each do |img| @wall.photos.create(image: img) end @photos = @wall.photos redirect_back(fallback_location: request.referer, notice: "Saved...") end end end walls.controller.rb class WallsController <

wrong number of arguments (given 1, expected 0)

核能气质少年 提交于 2021-02-11 14:49:59
问题 I want to upload photos to my website. After i selected the photos and click on "Add Photos" this error comes up. Any ideas how i can solve this? photos_controller.rb class PhotosController < ApplicationController def create @wall = Wall.find(params[:wall_id]) if params [:images] params[:images].each do |img| @wall.photos.create(image: img) end @photos = @wall.photos redirect_back(fallback_location: request.referer, notice: "Saved...") end end end walls.controller.rb class WallsController <

Heroku 'Could not detect rake tasks'

坚强是说给别人听的谎言 提交于 2021-02-11 07:12:02
问题 I have a legacy app deployed to Heroku that is suddenly failing to compile. It works fine locally, and had no problems when I last deployed it on 3/23. Now I'm trying to push a small change - a single link added to a view. I know this app is using unsupported versions of Ruby / Rails / Spreecommerce - 1.9.3 / 3.0.20 / 0.60. We have plans to update, but in the meantime I need to get this change live. The error from Heroku is: remote: ! Could not detect rake tasks remote: ! ensure you can run `

Heroku 'Could not detect rake tasks'

只谈情不闲聊 提交于 2021-02-11 07:11:12
问题 I have a legacy app deployed to Heroku that is suddenly failing to compile. It works fine locally, and had no problems when I last deployed it on 3/23. Now I'm trying to push a small change - a single link added to a view. I know this app is using unsupported versions of Ruby / Rails / Spreecommerce - 1.9.3 / 3.0.20 / 0.60. We have plans to update, but in the meantime I need to get this change live. The error from Heroku is: remote: ! Could not detect rake tasks remote: ! ensure you can run `

pg_search for an advanced search

谁都会走 提交于 2021-02-11 05:52:43
问题 I'm trying to figure out how to pass multiple parameters to my search using pg_search_gem and the pg_search_scope This is my simple search include PgSearch pg_search_scope :simple_search, against: [:title, :description], using: { tsearch: { dictionary: "spanish"} } def self.search(search) if search.present? simple_search(search) else find(:all) end end But now I'm trying to do something like this include PgSearch pg_search_scope :simple_search, against: [:title, :place, :category], using: {

pg_search for an advanced search

狂风中的少年 提交于 2021-02-11 05:51:27
问题 I'm trying to figure out how to pass multiple parameters to my search using pg_search_gem and the pg_search_scope This is my simple search include PgSearch pg_search_scope :simple_search, against: [:title, :description], using: { tsearch: { dictionary: "spanish"} } def self.search(search) if search.present? simple_search(search) else find(:all) end end But now I'm trying to do something like this include PgSearch pg_search_scope :simple_search, against: [:title, :place, :category], using: {