Forum: Ruby on Rails checkbox helper question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nola S. (Guest)
on 2006-02-26 00:39
(Received via mailing list)
I used scaffolding, then modified. As an after thought I added a
"boolean" checkbox to my database, form with this tag

<p>
<%= check_box 'is_hot_item', @photo.is_hot_item %>
<label for="is_hot_item">hot item?</label><br>
</p>

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

:(

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
Nola (Guest)
on 2006-02-26 01:24
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! .. :)


Nola S. wrote:
> I used scaffolding, then modified. As an after thought I added a
> "boolean" checkbox to my database, form with this tag
>
> <p>
> <%= check_box 'is_hot_item', @photo.is_hot_item %>
> <label for="is_hot_item">hot item?</label><br>
> </p>
>
> I check it and save. But I don't get 1 saved in my database field.
>
> :(
>
> 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
This topic is locked and can not be replied to.