Checkbox helper question

I used scaffolding, then modified. As an after thought I added a
“boolean” checkbox to my database, form with this tag

<%= check_box 'is_hot_item', @photo.is_hot_item %> hot item?

I check it and save. But I don’t get 1 saved in my database field.

:frowning:

I have just the regular old scaffolding code to save:

def create
@photo = Photo.new(params[:photo])
if @photo.save
flash[:notice] = ‘Photo was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(params[:photo])
flash[:notice] = ‘Photo was successfully updated.’
redirect_to :action => ‘show’, :id => @photo
else
render :action => ‘edit’
end
end

ant ideas???


http://PhpGirl.blogger.com

Nevermind … got it… have my checkbox params wrong. should be

<%= check_box ‘photo’, ‘is_hot_item’ %>

not

<%= check_box ‘is_hot_item’, @photo.is_hot_item %>

DOH! … :slight_smile:

Nola S. wrote:

I used scaffolding, then modified. As an after thought I added a
“boolean” checkbox to my database, form with this tag

<%= check_box 'is_hot_item', @photo.is_hot_item %> hot item?

I check it and save. But I don’t get 1 saved in my database field.

:frowning:

I have just the regular old scaffolding code to save:

def create
@photo = Photo.new(params[:photo])
if @photo.save
flash[:notice] = ‘Photo was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(params[:photo])
flash[:notice] = ‘Photo was successfully updated.’
redirect_to :action => ‘show’, :id => @photo
else
render :action => ‘edit’
end
end

ant ideas???


http://PhpGirl.blogger.com
http://CodeSnipers.com