Inverse function
String#underscore is inverse for the camelize.
==== "active_record".camelize.underscore # => "active_record"
Community contributions, tips, and corrections to the documentation. (1708 notes)
String#underscore is inverse for the camelize.
==== "active_record".camelize.underscore # => "active_record"
(also, you can use instance vars)
assert_select "div#event_#{assigns[event].id}", { :count => 0, :html => /something/ }
Maybe it used to not translate but I know it does as of 2.3.8. It is first lookup on the key:
helpers.label.<object_name>.<method_name>
If that doesn't return anything it will use the +human_attribute_name+ method on ActiveRecord::Base to translated which uses:
activerecord.attributes.<ob...
You can do
array[n..-1]
upplying any combination of +:confirm+, +:popup+, and/or +:method+ options to the link_to method results the +:onclick+ option being overridden.
Example: link_to "Delete", '#', :confirm=>"Are you sure?", :onclick=>"destroyJsFunction()" # expected output # => <a href="#" onclick="if(conf...
If you merge a normal Hash into a HashWithIndifferentAccess, then the keys will convert to strings...
This will likely bite you if the merge is passed to AR find: as netmaniac said "Beware, that using strings as association names, when giving Hash to :include will render errors".
Beware that param...
My add_index command was producing no change in my MySQL 5.0 database: add_index :designations, [ :scope_type, :scope_id, :role_id, :user_id ], :unique => true By just adding an index name, the problem was solved: add_index :designations, [ :scope_type, :scope_id, :role_id, :user_id ], :uniq...
If you want to use this in a test, add the following to test_helper.rb:
include ActionDispatch::TestProcess
(If using factory_girl, you can call it in your Factory, like so:
f.photo { fixture_file_upload 'test.png', 'image/png' }
In Rails 3, this has moved to ActionDispatch::TestProcess
(Which means, if you want to use it in a test, you need to add the following to test_helper.rb:)
include ActionDispatch::TestProcess
Please note that +stub_chain+ doesn't work outside of the +it...do...end+ block.
If you need to create more complicated chains using a function you need to use the old way.
For example, Google Custom Search's URL is http://www.google.com/jsapi
It's an ugly hack, but works:
= javascript_include_tag('http://www.google.com/jsapi').sub('.js', '')
See http://github.com/cementhorses/in_place_editing for the new plugin to use as a substitute.
You can redirect to your main page using
redirect_to :root
Make sure to configure to root route first:
use :null => false
change_column :my_table, :my_column, :integer, :default => 0, :null => false
I can change a column type from INT to BIGINT with this command:
change_column :my_table, :my_column, :bigint
See ActionDispatch::Routing for routing in Rails 3.
Oddly enough it runs a rake task without any sort of output. To get around it you can simple substitute it with:
puts run('rake your_task')
Unless somebody has a better idea?
Well, it's not here. For Rails 3 they are part of Thor::Actions
In the above example 'value' happens to be either true or false depending if the option was passed in or not. If you wish to capture an actual value you'll want something like this:
def add_options!(opt)
opt.on('-option=value') { |value| options[:option] = value }
end
You can scope uniqueness as well
validates :user_name, :presence => true, :uniqueness => {:scope => :account_id}
# the old way
validates_uniqueness_of :user_name, :scope => :account_id