Forum: Ruby on Rails More concise edit methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-02-24 02:05
def edit
  @item = Item.find(params[:id])

  redirect_to :action=>:list if (request.post? and
@item.update_attributes(params[:item]))
end

I could probably condense it into one line (something like
...and(@item=Item.update...)), but I'll probably actually use:

def edit
  @item = Item.find(params[:id])

  if request.post? and @item.update_attributes(params[:item])
    flash[:notice] = 'Item updated.'

    redirect_to :action=>:list
  end
end

I like this readable conciseness that's easily possible in Ruby/Rails.
:)

Joe
This topic is locked and can not be replied to.