Form parameter

How can I change some parameters in a function of the controller. I have
a User_Controller, who’s responsible for update the information fields
in the database.

The parameters are “id”, “firstname” and “lastname”. Now, I want to
manipulate parameter “lastname”, because I would like to add at the end
a point.

Thomas Miller ----->>> save in the database ------>>> Thomas Miller.

until now, I have the following codelines. But it doesn’t manipulate the
lastname-parameter. Can anyone help to manipulate this parameter?

Example:

def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:notice] = ‘User was successfully updated.’
redirect_to :action => ‘show’, :id => @user
else
render :action => ‘edit’
end
end

!!! Thanks for your help !!!

Hi –

On Tue, 8 Aug 2006, M. R. wrote:

until now, I have the following codelines. But it doesn’t manipulate the
lastname-parameter. Can anyone help to manipulate this parameter?

Example:

def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])

Add this:

   @user.update_attribute("lastname", @user.lastname + '.')

flash[:notice] = ‘User was successfully updated.’
redirect_to :action => ‘show’, :id => @user
else
render :action => ‘edit’
end
end

Another way, possible nicer, is to do it in the model, along the lines
of:

class User < AR::Base
before_save :add_dot
def add_dot
self.name += “.”
end
# …
end

David


http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack’s][ Web]log
http://www.manning.com/black => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.

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