Forum: Ruby on Rails help with form

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.
farocco (Guest)
on 2005-12-09 18:34
(Received via mailing list)
Hello,

I am getting a application error(rails) when I click the edit button.
What am I doing wrong?
Thanks
Frank

<%= start_form_tag :action => 'update', :id => @receipt %>
<table>
 <tr><td><b>Patient Information</b></td><td>&nbsp;</td></tr>
 <tr><td>Last Name</td><td><%= text_field("receipt","LAST", "size" =>
50) %></td></tr>

  <tr><td><%= submit_tag 'Edit' %></td></tr>
  </table>
<%= end_form_tag %>

def update
    @receipt = Receipt.find(params[:id])
    if @receipt.update_attributes(params[:receipt])
      flash[:notice] = 'Receipt was successfully updated.'
      redirect_to :action => 'show', :id => @receipt
    else
      render :action => 'edit'
    end
  end
farocco (Guest)
on 2005-12-09 20:39
(Received via mailing list)
Can someone pleas ehelp me with this?

Thanks

Frank
  ----- Original Message -----
  From: Frank
  To: removed_email_address@domain.invalid
  Sent: Friday, December 09, 2005 11:11 AM
  Subject: [Rails] help with form


  Hello,

  I am getting a application error(rails) when I click the edit button.
  What am I doing wrong?
  Thanks
  Frank

  <%= start_form_tag :action => 'update', :id => @receipt %>
  <table>
   <tr><td><b>Patient Information</b></td><td>&nbsp;</td></tr>
   <tr><td>Last Name</td><td><%= text_field("receipt","LAST", "size" =>
50) %></td></tr>

    <tr><td><%= submit_tag 'Edit' %></td></tr>
    </table>
  <%= end_form_tag %>

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


------------------------------------------------------------------------------


  _______________________________________________
  Rails mailing list
  removed_email_address@domain.invalid
  http://lists.rubyonrails.org/mailman/listinfo/rails
brianvh (Guest)
on 2005-12-09 20:56
(Received via mailing list)
Frank wrote:
> def update
>     @receipt = Receipt.find(params[:id])
>     if @receipt.update_attributes(params[:receipt])
>       flash[:notice] = 'Receipt was successfully updated.'
>       redirect_to :action => 'show', :id => @receipt

I've taken a look at your code twice, and this is the only thing that
jumped out
at me...

You're redirect_to action is trying to assign the entire Receipt record
as the
:id. Try changing it to ":id => @receipt.id".

-Brian
Daniel -. (Guest)
on 2005-12-12 00:06
(Received via mailing list)
Hi Frank,

I'm just curious.  Do you get anything returned with
@receipt = Receipt.find(params[:id])

On the initial load of the form the params[:id] will be present, but is
it
present when the form is submitted to the update action?

Cheers
Frank R. (Guest)
on 2005-12-12 01:00
(Received via mailing list)
Hi Brian,

I regenerated my app and it seems to work on my mac.
I am going to try it on my windows pc at work on Monday.

Regards,
Frank
This topic is locked and can not be replied to.