The last existing version
It says: The last existing version, and yet when I run a rails console in a 3.0.17 and try the method, it just works. Or does it mean it was never worked on past 2.3.8 ?
Community contributions, tips, and corrections to the documentation. (1708 notes)
It says: The last existing version, and yet when I run a rails console in a 3.0.17 and try the method, it just works. Or does it mean it was never worked on past 2.3.8 ?
I'd remove my original note if I could, but I can't see a way how.
If you want multiple options to be selected by default you can pass an array of values as "selected" option. It should be obvious, but odradek's and batarski's notes can confuse somebody in this case.
For reasons that are beyond my comprehension, this piece of code
class Working
include ActiveModel::Validations
attr_accessor :format
validates :format, :presence => true, :format => { :with => /\\AWorking/ }
end
works (NOTE: it has an attribute that has the same name of an...
To specify an accept header, you need to pass it in the second hash like this:
get '/url', nil, {'HTTP_ACCEPT' => 'application/json'}
The documentation says everything is uppercased and HTTP_ is appended when necessary, but that wasn't working for me.
You might not realize it preserves order because it delegates inspect to its super-class, Hash, which doesn’t preserve order. But you will see that order is preserved if you iterate or use the keys or values methods:
>> names = ['Amy Irving', 'Jane Doe', 'John Doe', 'John Updike', 'Susan Anthon...
You can avoid ActionController::DoubleRenderError (Can only render or redirect once per action) with #performed?
==== For example def index redirect_to not_found_path unless authenticated? render :action => 'update' unless performed? end
i.e.
helper.number_to_currency(187) => "190 kr"
check out your... translations! Especially 'significant' key... In my case it was
number: currency: format: significant: 'false'
that broke rounding. It should have been
number: currency: format: sig...
Found this the hard way, but to add an ID to the form generated by form_tag, you must explicitly make hashes.
==== Add ID <%= form_tag({:action => 'create'}, {:id => 'anID'}) %>
Enter the value in the 'value to check if exist in the list' section and the drop down should have that selected
==== Code example
select_tag "name",
options_for_select(list.collect{ [ text, value] },
'value to check if exist in the list',
{:include_blank =>...
Note that CGI::parse does not attempt to create a multi-level object; that is, it basically ignores hard brackets in key names.
For a method that does deal with these, see Rack::Utils.parse_nested_query.
@nZifnab it is a bad example because an included module is basically a class.
module Mod
def exit(code = 0)
puts "Exiting with code #{code}"
super
end
end
include Mod
exit 99
produces
Exiting with code 99
The Content-Disposition response header holds the suggested attachment filename (i.e. "attachment; filename=fname.ext")
Set the +:disposition+ option to pass this name.
=== Controller
http = Net::HTTP.new(@page.host)
res = http.post(path, info.to_query, headers)
send_data res, :conten...
I would like to point out that if you are on rails 2.3.11 or lower you will not be able to run ledermann code.
==== Ledermann Code user.messages.update_all(:read => true)
If you are running 2.3 or later it you will have to use James code
==== James Code
Message.update_all({:read => true...
Don't use constructs like this one, they won't work:
class User < ActiveRecord::Base
attr_accessible :name
attr_protected :id, :password_digest, :created_at, :updated_at, as: :admin
end
Instead, use the same method for all roles:
class User < ActiveRecord::Base
attr_access...
Replying to elfo's comment, you can achieve it easier, just add following line to /config/application.rb.
config.active_record.whitelist_attributes = true
All attributes in all models will be mass assignment protected by default. You can still use attr_accessible or attr_protected to override...
. user.save(false)
will skip validations
The result of this method is a hash of the following form:
{"table_field"=>"table value", "another_field" => 15, ...}
For example:
{"user_id"=>21}
We are soon launching DupCode.com, at which you can test and analyze your coding skills, compete with friends and at the same time pave the way to professional coder Come drop your email at DupCode.com and we will inform you the minute we launch!
It is possible to supply a class with own (de)serialization logic to the serialize call. Given object must respond to load and dump calls.
Following example serializes symbols into their string representation and store them in database as raw strings instead of their YAML representation, i.e. :pump...