I have a quick question on a problem of mine. I''ve done the ONLamp tutorial with scaffolding a recipe etc, and honesly I didn''t get really any wiser. So I decided to try it out on my own without scaffolding. However. Now I''m stuck with my edit-form. I need to update a row with old text in the ''pres'' column in the table called ''presentations'' in my database with a new text typed in with a form (in edit.rhtml). My Edit method gets the ''pres'' from the ''presentations''table but it doesn''t update the edited ''pres'' with the new text to the database when the submit button is clicked. I really can''t understand why not? What is wrong with my code? --------------------- Model --------------------- class Presentation < ActiveRecord::Base belongs_to :user end --------------------- controller --------------------- class PresentationController < ApplicationController def info @user_login = current_user.login @user_presentation = current_user.presentation.pres end def edit @presentation = current_user.presentation(params[:id]) end def update @presentation = current_user.presentation(params[:id]) if @presentation.update_attributes(params[:pres]) redirect_to :action => ''info'' else render :action => ''edit'' end end end --------------------- Edit view --------------------- <% form_tag :action => ''update'', :id => @presentation do %> <p><label for="pres">Edit Information</label><br/> <%= text_area ''presentation'', ''pres'' %></p> <p><%= submit_tag ''Update'' %></p> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 17 Jan 2008, at 11:58, Dag Stensson wrote:> > My Edit method gets the ''pres'' from the ''presentations''table but it > doesn''t update the edited ''pres'' with the new text to the database > when > the submit button is clicked. I really can''t understand why not? > What is > wrong with my code? > > > def update > @presentation = current_user.presentation(params[:id]) > if @presentation.update_attributes(params[:pres]) > redirect_to :action => ''info''[snip]> <p><label for="pres">Edit Information</label><br/> > <%= text_area ''presentation'', ''pres'' %></p>text_area (and other similar) helpers will make the submitted parameters available as params[:presentation] since that''s the name of the object you''re editing. Use if @presentation.update_attributes(params[:presentation]) and you should be fine. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you Fred for solving my problem and explaining! Im very greatful -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- attachment_fu and form_tag for multiple models?
- Help using tapply with multiple variables
- [PATCH] nouveau: add valid range tracking to nouveau_buffer
- Cannot get multipart => true , running well in my form when using remote => true
- net rpc vampire is sucking my brain!