syntax: render partial: "account"

17 views
Skip to first unread message

Jedrin

unread,
Mar 7, 2014, 12:54:53 PM3/7/14
to rubyonra...@googlegroups.com

The syntax of partial here does not make sense to me. If it was :partial then it's a symbol, but
what is it this way ?

<%= render partial: "account" %>

Antônio Augusto Sousa Britto

unread,
Mar 7, 2014, 1:07:47 PM3/7/14
to rubyonra...@googlegroups.com
its a hash of parameters to the render method ?!


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7b84d5c6-e796-45dd-aaf2-0810f6655390%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Att, Antônio Augusto de Sousa Britto - 43ª turma de Ciência da Computação - UFU

Jedrin

unread,
Mar 7, 2014, 1:27:41 PM3/7/14
to rubyonra...@googlegroups.com

this isn't valid syntax because of the colon at the end of 'something'

my_var = something:

this is not valid

key: 'car'

 If there is some shorthand or special case I do not understand

Jedrin

unread,
Mar 7, 2014, 1:32:32 PM3/7/14
to rubyonra...@googlegroups.com
so this is valid syntax then, I never realized that

{mykey: 'xx''}

=> {:mykey=>"xx"}

mike

unread,
Mar 7, 2014, 1:44:27 PM3/7/14
to rubyonra...@googlegroups.com
yes.  in hashes the longer, traditional form is:

<%= render :partial => "account" %>

you can now just write:

<%= render partial: "account" %>

actually, in the case of rendering a partial, usually you don't need to even say partial, you write:

<%= render "account" %>

the filename, if it's a partial, will begin with an underscore, such as _account.html.erb and rails will know it's a partial.  the only conflict would arise if you have both an account.html.erb and an _account.html.erb.   

Antônio Augusto Sousa Britto

unread,
Mar 7, 2014, 1:44:52 PM3/7/14
to rubyonra...@googlegroups.com
I guess it is the new hash notation. Not sure which version of Ruby implements it ( > 2.0 ?)


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages