Forum: Ruby on Rails I want to create text box but in run time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
mahmoud_cs (Guest)
on 2008-12-14 23:51
(Received via mailing list)
I want to create text box but in run time

when  I write in the controller for @a="input type ='text' "
and in the view <%=@a%> it display text box in the page when it run

but when  I write in the controller for @a="<%=text_field%>"
and in the view <%=@a%> it doesn't display text box in the page when
it run

how can i solve it
Joshua A. (Guest)
on 2008-12-15 02:31
There are two problems with that. One, all that's going to do is output
the text "text_field" not call the method. Second, text_field requires
two arguments object_name and method.

So anyway, use the send method to call the text_field method in the view
and pass in whatever args you need.


# Controller
@a = 'text_field'

# View
<%= send(@a, :object_name, :method) %>

Hope that helps.

-- Josh
http://iammrjoshua.com


mahmoud_cs wrote:
> I want to create text box but in run time
>
> when  I write in the controller for @a="input type ='text' "
> and in the view <%=@a%> it display text box in the page when it run
>
> but when  I write in the controller for @a="<%=text_field%>"
> and in the view <%=@a%> it doesn't display text box in the page when
> it run
>
> how can i solve it
mahmoud_cs (Guest)
on 2008-12-15 22:53
(Received via mailing list)
On Dec 15, 2:31 am, Joshua A. <removed_email_address@domain.invalid>
wrote:
> # View
> <%= send(@a, :object_name, :method) %>
>
> Hope that helps.
>
> -- Joshhttp://iammrjoshua.com
>

unfortunately it didn't work
it display that error                undefined method ` text_field '
hyuan (Guest)
on 2008-12-16 05:02
(Received via mailing list)
Ahmed A. (Guest)
on 2008-12-16 11:17
(Received via mailing list)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="direction: ltr;">
<head>
  <meta content="text/html;charset=windows-1256"
 http-equiv="Content-Type">
</head>
<body style="direction: ltr;" bgcolor="#ffffff" text="#000000">
<p style="margin-bottom: 0cm; margin-top: 0pt;"><font
 face="Helvetica, Arial, sans-serif">How about creating a hidden DIV
that include the text box, and make it appears
programatically.</font><br>
</p>
<div class="moz-signature">
<title></title>
<div class="moz-signature">
<div class="moz-signature"><br>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><font
face="Arial">Regards,...</font></p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
</p>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><font
face="Arial"><b><big>Ahmed
Abdelsalam</big></b></font>
</p>
</div>
</div>
</div>
<p style="margin-bottom: 0cm; margin-top: 0pt;"><br>
<br>
hyuan wrote:<br>
</p>
<blockquote
 cite="mid:removed_email_address@domain.invalid"
 type="cite">
  <pre wrap="">text_field_tag

See:

<a class="moz-txt-link-freetext"
href="http://api.rubyonrails.com/classes/ActionView/Help...

On Dec 15, 12:52 pm, mahmoud_cs <a class="moz-txt-link-rfc2396E"
href="mailto:removed_email_address@domain.invalid">&lt;removed_email_address@domain.invalid&gt;</a>
wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">On Dec 15, 2:31 am, Joshua A. <a
class="moz-txt-link-rfc2396E"
href="mailto:removed_email_address@domain.invalid">&lt;removed_email_address@domain.invalid&gt;</a>
wrote:



    </pre>
    <blockquote type="cite">
      <pre wrap="">There are two problems with that. One, all that's
going to do is output
the text "text_field" not call the method. Second, text_field requires
two arguments object_name and method.
      </pre>
    </blockquote>
    <blockquote type="cite">
      <pre wrap="">So anyway, use the send method to call the text_field
method in the view
and pass in whatever args you need.
      </pre>
    </blockquote>
    <blockquote type="cite">
      <pre wrap=""># Controller
@a = 'text_field'
      </pre>
    </blockquote>
    <blockquote type="cite">
      <pre wrap=""># View
&lt;%= send(@a, :object_name, :method) %&gt;
      </pre>
    </blockquote>
    <blockquote type="cite">
      <pre wrap="">Hope that helps.
      </pre>
    </blockquote>
    <blockquote type="cite">
      <pre wrap="">-- Joshhttp://iammrjoshua.com
      </pre>
    </blockquote>
    <pre wrap="">unfortunately it didn't work
it display that error                undefined method ` text_field '
    </pre>
  </blockquote>
  <pre wrap=""><!---->

  </pre>
</blockquote>
<br>
--~--~---------~--~----~------------~-------~--~----~<br>
You received this message because you are subscribed to the Google
Groups &quot;Ruby on Rails: Talk&quot; group. <br> To post to this
group, send email to removed_email_address@domain.invalid <br> To
unsubscribe from this group, send email to
removed_email_address@domain.invalid <br> For more options,
visit this group at
http://groups.google.com/group/rubyonrails-talk?hl...
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
This topic is locked and can not be replied to.