Forms, database, and yes I'm new

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 %>

Edit Information
<%= text_area 'presentation', 'pres' %>

<%= submit_tag 'Update' %>

<% end %>

On 17 Jan 2008, at 11:58, Dag S. wrote:

@presentation = current_user.presentation(params[:id])
if @presentation.update_attributes(params[:pres])
redirect_to :action => ‘info’
[snip]

Edit Information
<%= text_area 'presentation', 'pres' %>

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

Thank you Fred for solving my problem and explaining! Im very greatful

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs