On 10/18/07, Fjan <jmfaber-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> I get a warning "render :nothing deprecated, use render :file
> instead"... but I cannot find any info on how to use render :file to
> render nothing. It''s also not mentioned on the deprecated items
web
> page, it this warning a bug?
To add to what Fred said, you may be wondering why you need
:nothing => true
instead of just
:nothing
The reason is that you used to be able to write:
render "path/to/some_file.rhtml"
which was equivalent to
render_file "path/to/some_file.rhtml"
The Rails guys decided to get rid of all the render_xxx methods and
just have a single render method that takes a hash of options:
render :action => ''blah''
render :file => ''blech''
render :inline => ''<%= foo %>''
In order to provide backward compatibility, render looks at its
argument. If it''s a Hash, it''s treated as the new-style way of
doing
things. Otherwise, it''s assume to be the old render
"some_file"
method, so the argument gets passed along to render_file, and a
deprecation warning is issued (since this will go away completely in
Rails 2.0).
So, with all that background,
render :nothing
actually is transformed into
render :file => :nothing
which isn''t what you intended.
By writing
render :nothing => true
render receives a Hash as it''s argument (because of the =>
operator),
so you get nothing rendered.
Ruby has an interesting feature in method calls, where a Hash literal
and the *end* of a parameter list does not need to be enclosed in
braces. So
render :nothing => true
is really the same as
render({:nothing => true})
It''s a nice feature, because it cuts down on the "line noise"
so
common with Perl e.g., but you need to be aware of it because it can
be misleading. For example:
update_attribute :foo, "Bar" # two arguments passed
update_attributes :foo => "Bar" # *one* argument (a Hash)
passed
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---