# I want to create text box but in run time

**URL:** <https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627>\
**Category:** Rails\
**Created:** [December 14, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627 "2008-12-14T22:51:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahmoud\_cs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@mahmoud\_cs](https://www.ruby-forum.com/u/mahmoud_cs)\
**Post date:** [December 14, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627/1 "2008-12-14T22:51:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mahmoud\_cs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@mahmoud\_cs](https://www.ruby-forum.com/u/mahmoud_cs)\
**Post date:** [December 15, 2008, 1:31am UTC](https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627/2 "2008-12-15T01:31:35Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![mahmoud\_cs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@mahmoud\_cs](https://www.ruby-forum.com/u/mahmoud_cs)\
**Post date:** [December 15, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627/3 "2008-12-15T21:53:51Z")

</div>

On Dec 15, 2:31 am, Joshua A. [removed\_email\_address@domain.invalid](mailto: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 ’

---

<div class="post-metadata">

**Author:** ![mahmoud\_cs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@mahmoud\_cs](https://www.ruby-forum.com/u/mahmoud_cs)\
**Post date:** [December 16, 2008, 4:02am UTC](https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627/4 "2008-12-16T04:02:31Z")

</div>

text\_field\_tag

See:

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html)

---

<div class="post-metadata">

**Author:** ![mahmoud\_cs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e56c9b/32.png) [@mahmoud\_cs](https://www.ruby-forum.com/u/mahmoud_cs)\
**Post date:** [December 16, 2008, 10:17am UTC](https://www.ruby-forum.com/t/i-want-to-create-text-box-but-in-run-time/155627/5 "2008-12-16T10:17:36Z")

</div>

How about creating a hidden DIV that include the text box, and make it appears programatically.

  

Regards,...

**Ahmed Abdelsalam**

hyuan wrote:

> ```
> text_field_tag
> 
> See:
> 
> [http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html)
> 
> On Dec 15, 12:52 pm, mahmoud\_cs [\<removed\_email\_address@domain.invalid\>](mailto:removed_email_address@domain.invalid)  
> wrote:
> ```
> 
> > ```
> > On Dec 15, 2:31 am, Joshua A.[\<removed\_email\_address@domain.invalid\>](mailto:removed_email_address@domain.invalid)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.
> > ```
> 
>   
> 
> > ```
> > 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.
> > ```
> 
>   
> 
> > ```
> > – Joshhttp://iammrjoshua.com
> > ```
> 
>   
> 
> ```
> unfortunately it didn’t work
> it display that error undefined method ` text_field ’
> ```

```

```
  
--~--~---------~--~----~------------~-------~--~----~  
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 removed\_email\_address@domain.invalid   
 To unsubscribe from this group, send email to removed\_email\_address@domain.invalid   
 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en  
-~----------~----~----~----~------~----~------~--~---
