# Making a Little Application

**URL:** <https://www.ruby-forum.com/t/making-a-little-application/156370>\
**Category:** Rails\
**Created:** [December 26, 2008, 12:23am UTC](https://www.ruby-forum.com/t/making-a-little-application/156370 "2008-12-26T00:23:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 26, 2008, 12:23am UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/1 "2008-12-26T00:23:53Z")

</div>

Hi everyone.

I am really new to Ruby on Rails, so I apologize if this is a really  
simple question but I just can’t think of how I could do this. I want  
there to be a button that will add a drop down menu to the screen, and  
then depending on what the user selects it will add either a text  
field or a text “area” it will add the selected one to the right of  
the menu. Also, the user would have to be allowed to delete certain  
“fields” as well. Then when the user submits the form Ruby on Rails  
will be able to see how many menus were made as well as read what the  
user put in all of them. I hope this makes sense, but if it doesn’t,  
just ask for clarification. 🙂

If anyone could help, it would be great.

---

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 26, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/2 "2008-12-26T17:23:06Z")

</div>

On Thu, Dec 25, 2008 at 5:55 PM, Pierce [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> will be able to see how many menus were made as well as read what the  
> user put in all of them. I hope this makes sense, but if it doesn’t,  
> just ask for clarification. 🙂
> 
> If anyone could help, it would be great.

Hello Peirce,  
I am a newbie myself, so take any ideas I give you with a great big  
grain of  
salt, but I think you have two options here:

1. Instead of a button, use a link. Then, when the user clicks on the  
link,  
your controller could gather the information submitted (such as what was  
selected) and redirect the browser to a new page which would present the  
same information plus either a text field or a text area. This has the  
benefit of simplicity and sticks with what you probably already know  
(hopefully), but it will be somewhat clunky and look different than the  
more  
modern way of doing what you describe.

2. The more modern way of doing what you describe is to use JavaScript  
and  
AJAX to dynamically render new portions of your page dependent upon what  
the  
user has entered so far. This has the benefit of looking very slick  
when  
done well, but requires that you learn something about JavaScript and  
AJAX.  
Fortunately, there are a lot of resources (in the form of web pages with  
tutorials as well as a plethora of books at your local technical  
bookstore).

Hopefully, these couple of ideas will get you thinking in one direction  
or  
another.

–wpd

---

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 26, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/3 "2008-12-26T20:56:50Z")

</div>

Pierce wrote:

> Hi everyone.
> 
> I am really new to Ruby on Rails, so I apologize if this is a really  
> simple question but I just can’t think of how I could do this. I want  
> there to be a button that will add a drop down menu to the screen, and  
> then depending on what the user selects it will add either a text  
> field or a text “area” it will add the selected one to the right of  
> the menu. Also, the user would have to be allowed to delete certain  
> “fields” as well. Then when the user submits the form Ruby on Rails  
> will be able to see how many menus were made as well as read what the  
> user put in all of them. I hope this makes sense, but if it doesn’t,  
> just ask for clarification. 🙂
> 
> If anyone could help, it would be great.

Hi Pierce,

Your example is explained in a difficult way. Could you point at an  
example on a existing website?

Actually, what you describe here is pretty much a lot of UI stuff, this  
can be done with AJAX and showing / hiding html elements.

Thanks,  
Michael

---

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 26, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/4 "2008-12-26T23:17:13Z")

</div>

Ruby on Rails in not a magic wand even you can do a magical stuff with  
it.  
I have read your description a couple of times and with a “I am  
missing something” filing.  
Perhaps you should first do a simple paper prototyping and then when  
all actions are known and clear move to implementation.

Since this look like a simple web application, more like a students  
homework, perhaps the Ruby on Rails is not a right tool for it.  
Take look at Sinatra [http://sinatra.rubyforge.org/](http://sinatra.rubyforge.org/) perhaps it’s  
sufficient framework for your task.

On Dec 26, 8:56 pm, Michael Hendrickx \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 27, 2008, 3:30am UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/5 "2008-12-27T03:30:32Z")

</div>

@Patrick D.

I don’t know about the first suggestion, but I know that the second  
option can work but brings up some problems… For example, when the  
page is refreshed the user looses all of the new fields. Also, it  
gets hard to manage in Javascript (at least the way that is below)  
because it gets a lot of code.

@Michael Hendrickx

Yeah, I kind of assumed it was hard to hard to understand. 🙂 I have  
wrote a quick example using Javascript, which is below this text. I  
know how to do this in Javascript, but there are some problems so I am  
looking if there is a way to do this in Ruby on Rails. The problems  
with doing it in Javascript are outlined above.

@Dejan D.

As I said, I kind of guessed that it would be hard to understand. I  
hope the code below makes more sense, but if not just say so and I  
will try to explain it better. Pretty much, a button/link creates a  
new object and shows it on the page. Preferably it would not loose  
the new fields (and their values) on a refresh. I am doing a rewrite  
of a web application in Ruby on Rails, and am wondering how to avoid  
doing this in Javascript again.

I suppose there really isn’t a reason why I need to do this in Ruby on  
Rails, but Javascript brings up some problems and I think it may be  
easier in Ruby on Rails in general. If anyone could give me some  
advice about this, it would be great.

---

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 30, 2008, 4:27am UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/6 "2008-12-30T04:27:02Z")

</div>

Sorry for the bump, but I am about to begin the rewrite and am  
wondering if there is some way to do this in Rails.

---

<div class="post-metadata">

**Author:** ![Pierce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ea5d25/32.png) [@Pierce](https://www.ruby-forum.com/u/Pierce)\
**Post date:** [December 27, 2008, 3:32am UTC](https://www.ruby-forum.com/t/making-a-little-application/156370/7 "2008-12-27T03:32:17Z")

</div>

Code:

Script Example Add
