On Sun, Nov 14, 2010 at 1:37 AM, Hanan Y. <[email protected]> wrote:

> Hi all,
> after allllooottt of research i found i could create a list box with
> this code :
>
>       <select name="itms[]" multiple="multiple" size="15">
>        <option></option>
>
>        <%= options_from_collection_for_select
> @items,:imei,:type_name,$var %><br/><br/>
>        </select>
>        <br> </br>
>
> This will create the list box i was craving for, and populate it with
> the items values from the DB , my question is this..
>
> 1) How can i create this list box with no values and be able to add
> values to it as needed
>

Someone else might have better idea, but from what I have seen you will need
to create a text box and an add button, when you submit the add button use
javascript to add the item to the list box. I think you will be adding both
an index and the text displayed.

I still really dont understand why you dont want to do it the other way,
again maybe I dont understand youir final outcome -- but as far as I can
understand the functionally on your page the result would be about the same,
but this is what I would do if I needed to. Also note, that in my opinion
you are beginning to fight Rails but trying to go outside and do something
manually.... in my experience I have always fared better by using
conventions and existing functionality whenever possible, as I have found
that when I do not, I end up coming upon special cases I did not think of
and end up investing a lot more time (and usually end up going back and
doing it the Rails way).


> 2) Once i have a listbox with the new values how can i loop though the
> values and submit each one to the db as a new value ?
>

You can request the params from the page in your controller.

So for example I think you could do something like (there are more concise
ways and you will probably have to play around with it go get it to work --
just turn on the debugger):

params[:itms].each do |itm|
   item = Item.new
   item.name = itm[:name]
   item.save
end


>
> Thanks. :)
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to