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