Hi everyone,
I''m building partial and I need to use a variable inside of another
variable name:
I''ve tried like this:
<div class="form_row">
<label for="<%= field %>"><%= field_title ||
field.humanize %>:</
label>
<%= form.text_field field,
:size => User::field.upcase_SIZE,
:maxlength => User::field.upcase_MAX_LENGTH %>
</div>
like this:
<div class="form_row">
<label for="<%= field %>"><%= field_title ||
field.humanize %>:</
label>
<%= form.text_field field,
:size => User::#{field.upcase}_SIZE,
:maxlength => User::#{field.upcase}_MAX_LENGTH
%>
</div>
and like this:
<div class="form_row">
<label for="<%= field %>"><%= field_title ||
field.humanize %>:</
label>
<%= form.text_field field,
:size => User::{field.upcase}_SIZE,
:maxlength => User::{field.upcase}_MAX_LENGTH
%>
</div>
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:
<div class="form_row">
<label for="email">Email:</label>
<%= form.text_field :email,
:size => User::EMAIL_SIZE,
:maxlength => User::EMAIL_MAX_LENGTH %>
</div>
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!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On 18 Nov 2007, at 00:45, Thiago Guerra wrote:> > Hi everyone, > > I''m building partial and I need to use a variable inside of another > variable name: > > and what I want to be displayed in this case is: > > <div class="form_row"> > <label for="email">Email:</label> > <%= form.text_field :email, > :size => User::EMAIL_SIZE, > :maxlength => User::EMAIL_MAX_LENGTH %> > </div> > > but I will also use it for another fields rather than just email. >you probably want to look at const_get. Fred> In PHP I know I could simply do it by ${all_${name}_text} but how does > it work with ruby on rails? > > Thanks! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Fred!
I got it working wonderfully with:
<% field_title = nil if not defined?(field_title) -%>
<div class="form_row">
<label for="<%= field %>"><%= field_title ||
field.humanize %>:</
label>
<%= form.text_field field,
:size => User::const_get(field.upcase +
"_SIZE"),
:maxlength => User::const_get(field.upcase +
"_MAX_LENGTH") %>
</div>
On Nov 18, 10:37 am, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 18 Nov 2007, at 00:45, Thiago Guerra wrote:
>
>
>
>
>
> > Hi everyone,
>
> > I''m building partial and I need to use a variable inside of
another
> > variable name:
>
> > and what I want to be displayed in this case is:
>
> > <div class="form_row">
> > <label for="email">Email:</label>
> > <%= form.text_field :email,
> > :size => User::EMAIL_SIZE,
> > :maxlength => User::EMAIL_MAX_LENGTH %>
> > </div>
>
> > but I will also use it for another fields rather than just email.
>
> you probably want to look at const_get.
>
> Fred
>
> > In PHP I know I could simply do it by ${all_${name}_text} but how does
> > it work with ruby on rails?
>
> > Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---