SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    updating single column with form

    I can't seem to find a tutorial on how to do this.

    Here's what i have in my controller
    Code Ruby:
      def update_lang_pref
        @language = Person.find(session[:user])
     
        if @language.update_attributes(:lang_pref)
          redirect_to request.env['HTTP_REFERER']
      end

    and i'm getting an error "can't dup Symbol". Parameters is reading "lang_pref"=>"1"


    what am i doing wrong? Any help is appreciated.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I'm still too new to know what the problem is. But I found this in a tutorial's file.
    Code Ruby:
      def update
        @forum = Forum.find(params[:id])
     
        respond_to do |format|
          if @forum.update_attributes(params[:forum])
            flash[:notice] = 'Forum was successfully updated.'
            format.html { redirect_to(@forum) }
            format.xml  { head :ok }
          else
            format.html { render :action => "edit" }
            format.xml  { render :xml => @forum.errors, :status => :unprocessable_entity }
          end
        end
      end
    The differences I see are that the second symbol is inside a sub and the use of "params".

  3. #3
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's the solution i ended up finding... good ol' update_ATTRIBUTE

    Code Ruby:
    if @language.update_attribute('lang_pref',params[:lang_pref])
       blah, blah, blah    
    end

    so apparently there's some contention out there because it doesn't validate, BUT because i'm trying to change a single integer from radio buttons, i'm not to worried about validation at the moment.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use the plural update_attributes and pass in a hash, it will validate:
    Code:
    @language.update_attributes({:lang_pref => params[:lang_pref]})

  5. #5
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ReggieB View Post
    If you use the plural update_attributes and pass in a hash, it will validate:
    Code:
    @language.update_attributes({:lang_pref => params[:lang_pref]})
    nope... didn't work for me.

    thanks though.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •