SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: updating single column with form
-
Feb 23, 2009, 10:52 #1
- Join Date
- Dec 2004
- Location
- illinois
- Posts
- 978
- 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...
-
Feb 23, 2009, 14:14 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 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
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Feb 23, 2009, 18:08 #3
- Join Date
- Dec 2004
- Location
- illinois
- Posts
- 978
- 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...
-
Feb 24, 2009, 09:30 #4
- 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]})
-
Feb 24, 2009, 11:36 #5
Bookmarks