Forum: Ruby on Rails help - edit without using scaffold

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.
Frank (Guest)
on 2006-01-05 20:57
(Received via mailing list)
Hello,

What am I doing wrong? The code below does not show the current record
for editing.

def edit
  @user = User.find(params[:id])
end

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
********************************************************************
<h1>Editing user</h1>
<%= form_tag :action => 'update', :id => @user %>
<table>
 <tr>
  <td>User Name:</td>
  <td><%= text_field("user", "username") %></td>
 </tr>
 <tr>
  <td>Login:</td>
  <td><%= text_field("user", "login") %></td>
 </tr>
 <tr>
  <td>Password:</td>
  <td><%= password_field("user", "password") %></td>
 </tr>
 <tr>
  <td>Email:</td>
  <td><%= text_field("user", "email") %></td>
 </tr>
 <tr>
  <td>Security:</td>
  <td><%= select("user", "role", [ ['User', 1], ['Supervisor', 2],
['Administrator', 3] ] ) %></td>
 </tr>
 <tr>
  <td></td>
  <td><input type="submit" value=" Edit User " />
 </tr>
</table>
<%= end_form_tag %>
<%= link_to 'Show', :action => 'show', :id => @user %> |
<%= link_to 'Back', :action => 'list_users' %>

********************************************************************
<table>
<% for user in @all_users -%>
<tr>
  <td><%= user.username %></td>
  <td><%= link_to("(edit)", :action => :edit_user, :id => user.id)
%></td>
  <td><%= link_to("(delete)", :action => :delete_user, :id => user.id)
%></td>
</tr>
<% end -%>
Frank (Guest)
on 2006-01-05 22:12
(Received via mailing list)
Hello,

I still cannot get this working.
How do I edit a record without using scaffold?

Thanks

Frank
  ----- Original Message -----
  From: Frank
  To: removed_email_address@domain.invalid
  Sent: Thursday, January 05, 2006 1:13 PM
  Subject: [Rails] help - edit without using scaffold


  Hello,

  What am I doing wrong? The code below does not show the current record
for editing.

  def edit
    @user = User.find(params[:id])
  end

  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
  ********************************************************************
  <h1>Editing user</h1>
  <%= form_tag :action => 'update', :id => @user %>
  <table>
   <tr>
    <td>User Name:</td>
    <td><%= text_field("user", "username") %></td>
   </tr>
   <tr>
    <td>Login:</td>
    <td><%= text_field("user", "login") %></td>
   </tr>
   <tr>
    <td>Password:</td>
    <td><%= password_field("user", "password") %></td>
   </tr>
   <tr>
    <td>Email:</td>
    <td><%= text_field("user", "email") %></td>
   </tr>
   <tr>
    <td>Security:</td>
    <td><%= select("user", "role", [ ['User', 1], ['Supervisor', 2],
['Administrator', 3] ] ) %></td>
   </tr>
   <tr>
    <td></td>
    <td><input type="submit" value=" Edit User " />
   </tr>
  </table>
  <%= end_form_tag %>
  <%= link_to 'Show', :action => 'show', :id => @user %> |
  <%= link_to 'Back', :action => 'list_users' %>

  ********************************************************************
  <table>
  <% for user in @all_users -%>
  <tr>
    <td><%= user.username %></td>
    <td><%= link_to("(edit)", :action => :edit_user, :id => user.id)
%></td>
    <td><%= link_to("(delete)", :action => :delete_user, :id => user.id)
%></td>
  </tr>
  <% end -%>


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


  _______________________________________________
  Rails mailing list
  removed_email_address@domain.invalid
  http://lists.rubyonrails.org/mailman/listinfo/rails
Frank (Guest)
on 2006-01-05 22:54
(Received via mailing list)
nevermind, I had the controller edit coded wrong.

Frank
  ----- Original Message -----
  From: Frank
  To: removed_email_address@domain.invalid
  Sent: Thursday, January 05, 2006 3:10 PM
  Subject: Re: [Rails] help - edit without using scaffold


  Hello,

  I still cannot get this working.
  How do I edit a record without using scaffold?

  Thanks

  Frank
    ----- Original Message -----
    From: Frank
    To: removed_email_address@domain.invalid
    Sent: Thursday, January 05, 2006 1:13 PM
    Subject: [Rails] help - edit without using scaffold


    Hello,

    What am I doing wrong? The code below does not show the current
record for editing.

    def edit
      @user = User.find(params[:id])
    end

    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
    ********************************************************************
    <h1>Editing user</h1>
    <%= form_tag :action => 'update', :id => @user %>
    <table>
     <tr>
      <td>User Name:</td>
      <td><%= text_field("user", "username") %></td>
     </tr>
     <tr>
      <td>Login:</td>
      <td><%= text_field("user", "login") %></td>
     </tr>
     <tr>
      <td>Password:</td>
      <td><%= password_field("user", "password") %></td>
     </tr>
     <tr>
      <td>Email:</td>
      <td><%= text_field("user", "email") %></td>
     </tr>
     <tr>
      <td>Security:</td>
      <td><%= select("user", "role", [ ['User', 1], ['Supervisor', 2],
['Administrator', 3] ] ) %></td>
     </tr>
     <tr>
      <td></td>
      <td><input type="submit" value=" Edit User " />
     </tr>
    </table>
    <%= end_form_tag %>
    <%= link_to 'Show', :action => 'show', :id => @user %> |
    <%= link_to 'Back', :action => 'list_users' %>

    ********************************************************************
    <table>
    <% for user in @all_users -%>
    <tr>
      <td><%= user.username %></td>
      <td><%= link_to("(edit)", :action => :edit_user, :id => user.id)
%></td>
      <td><%= link_to("(delete)", :action => :delete_user, :id =>
user.id) %></td>
    </tr>
    <% end -%>


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


    _______________________________________________
    Rails mailing list
    removed_email_address@domain.invalid
    http://lists.rubyonrails.org/mailman/listinfo/rails



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


  _______________________________________________
  Rails mailing list
  removed_email_address@domain.invalid
  http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.