Hi everyone,
I’m building partial and I need to use a variable inside of another
variable name:
I’ve tried like this:
<%= field_title || field.humanize %>:
<%= form.text_field field,
:size => User::field.upcase_SIZE,
:maxlength => User::field.upcase_MAX_LENGTH %>
like this:
<%= field_title || field.humanize %>:
<%= form.text_field field,
:size => User::#{field.upcase}_SIZE,
:maxlength => User::#{field.upcase}_MAX_LENGTH
%>
and like this:
<%= field_title || field.humanize %>:
<%= form.text_field field,
:size => User::{field.upcase}_SIZE,
:maxlength => User::{field.upcase}_MAX_LENGTH
%>
To help you understand what I want:
I will call the partial on my view using this code:
<% render :partial => “text_field_row”, :field => “email”, :locals =>
{ :form => form } %>
and what I want to be displayed in this case is:
Email:
<%= form.text_field :email,
:size => User::EMAIL_SIZE,
:maxlength => User::EMAIL_MAX_LENGTH %>
but I will also use it for another fields rather than just email.
In PHP I know I could simply do it by ${all_${name}_text} but how does
it work with ruby on rails?
Thanks!
On 18 Nov 2007, at 00:45, Thiago G. wrote:
<%= form.text_field :email,
:size => User::EMAIL_SIZE,
:maxlength => User::EMAIL_MAX_LENGTH %>
but I will also use it for another fields rather than just email.
you probably want to look at const_get.
Fred
Thanks Fred!
I got it working wonderfully with:
<% field_title = nil if not defined?(field_title) -%>
<%= field_title || field.humanize %>:
<%= form.text_field field,
:size => User::const_get(field.upcase +
"_SIZE"),
:maxlength => User::const_get(field.upcase +
"_MAX_LENGTH") %>
On Nov 18, 10:37 am, Frederick C. [email protected]