Default_url in Paperclip Broke with Asset Pipeline Upgrade
:default_url => ActionController::Base.helpers.asset_path(‘missing_:style.png’) Then put the default images in app/assets/images/
:default_url => ActionController::Base.helpers.asset_path(‘missing_:style.png’) Then put the default images in app/assets/images/
Update your model to this class Car < ActiveRecord::Base # depending on how you deal with mass-assignment # protection in newer Rails versions, # you might want to uncomment this line # # attr_accessible :skip_method_2 attr_accessor :skip_method_2 validate :method_1, :method_3 validate :method_2, unless: :skip_method_2 private # encapsulation is cool, so we are cool # custom … Read more
With regards to the conditions with counter_cache, I would read this blog post. The one thing you should do is add the following to the migration file: add_column :employees, :projects_count, :integer, :default => 0, :null => false Employee.reset_column_information Employee.all.each do |e| Employee.update_counters e.id, :projects_count => e.projects.length end So you current projects count can get migrated … Read more
If you want all your links to be able to switch between http and https, you have to stop using the _path helper and switch to _url helpers. After that, using a scope with the protocol parameter forced and protocol constraint makes the urls automatically switch. routes.rb scope :protocol => ‘https://’, :constraints => { :protocol … Read more
At a high level, the intent of resource is to declare that only one of these resources will ever exist. For example: resource :profile, :only => [:edit, :update] As a user, I should only be able to update my own profile. I should never be able to edit other users’ profiles, so there’s no need … Read more
This might be a little verbose but I had to spend some time with the Rails source code to learn how the caching internals work. Writing things down aids my understanding and I figure that sharing some notes on how things work can’t hurt. Skip to the end if you’re in a hurry. Why It … Read more
Apparently ubuntu and ruby don’t always catch dependencies like they should. From the first google hit (yeah, I clicked on this stack-overflow in place #2 before checking out the first result.) Navigate to the Ruby source and enter: sudo apt-get install libreadline5-dev cd ext/readline ruby extconf.rb make sudo make install So, if you’re on another … Read more
This is because attributes/associations are actually methods(getters/setters) and not local variables. When you state “parent = value” Ruby assumes you want to assign the value to the local variable parent. Somewhere up the stack there’s a setter method “def parent=” and to call that you must use “self.parent = ” to tell ruby that you … Read more
You can define a new class in your application at lib/ext/string.rb and put this content in it: class String def to_magic “magic” end end To load this class, you will need to require it in your config/application.rb file or in an initializer. If you had many of these extensions, an initializer is better! The way … Read more
What’s happening is that “#{@user_name}” is being interpreted as CoffeeScript, not as Ruby code that’s evaluated and injected into the CoffeeScript source. You’re asking, “How do I inject a Ruby variable into my CoffeeScript source?” The short answer is: Don’t do this. The Rails team made an intentional decision not to support embedded CoffeeScript in … Read more