How to add multiple weekdays into one field

newbee question:

I have a form, where I want to add a choice of weekdays a movie is
playing into one field:

<%= select_tag ‘days[]’, options_for_select([[“monday”, “2”],
[“tuesday”, “3”], [“wednesday”, “4”], [“thursday”, “5”], [“friday”,
“6”], [“saturday”, “7”], [“sunday”, “1”]]),:multiple => true %>

how can I save days.join(",") into @movie.weekdays when I create a new
movie record?

def create
@movie = Movie.new(params[:movie])
respond_to do |format|
if @movie.save
flash[:notice] = ‘Movie was successfully created.’
format.html { redirect_to(movies_path) }
else
format.html { render :action => “new” }
end
end
end

On Sun, Sep 13, 2009 at 6:52 AM, arwed [email protected] wrote:

how can I save days.join(",") into @movie.weekdays when I create a new
movie record?

def create

I’d use merge right about here:

params[:movie].merge( :days => days.join(’,’) )

http://www.ruby-doc.org/core/classes/Hash.html#M002880

@movie = Movie.new(params[:movie])
respond_to do |format|
if @movie.save
flash[:notice] = ‘Movie was successfully created.’
format.html { redirect_to(movies_path) }
else
format.html { render :action => “new” }
end
end
end


Greg D.
http://destiney.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs