I started out with a normal scaffold for the USERS table. I changed the index view to be list.html.erb but the url: '/users/list' returns an 'unknown action' error. '/users/list/:id' also returns an 'unknown action' error. I've also merged both the edit and new views into the manage.html.erb which duplicates the list view except with a form on the right side. the url '/users/manage' returns an 'unknown action' error but '/users/manage/:id' brings me to the manage page with the edit form.
in my routes.rb, it reads: map.resources :users
The update an delete actions work but they don't route me to the right url. the new action does not work. can anyone help? I've pasted my controller and views below.
USERS CONTOLLER class UsersController < ApplicationController
layout 'staff'
def index list render :action => 'list' end
# GET /users # GET /users.xml def list @users = User.find(:all)
# respond_to do |format| # format.html # index.html.erb # format.xml { render :xml => @users } # end end
# GET /users/new # GET /users/new.xml def manage list @user = User.find(params[:id]) if params[:id] @user = User.new if @user.nil?
# respond_to do |format| # format.html # new.html.erb # format.xml { render :xml => @user } # end end
# POST /users # POST /users.xml def create @user = User.new(params[:user])
respond_to do |format| if @user.save flash[:notice] = 'User was successfully created.' format.html { redirect_to(users_url) } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render(:action => "manage") } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end
# PUT /users/1 # PUT /users/1.xml def update @user = User.find(params[:id])
respond_to do |format| if @user.update_attributes(params[:user]) flash[:notice] = 'User was successfully updated.' format.html { redirect_to(users_url) } format.xml { head :ok } else format.html { render(:action => 'manage') } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end
# DELETE /users/1 # DELETE /users/1.xml def destroy @user = User.find(params[:id]) @user.destroy
respond_to do |format| flash[:notice] = 'User was successfully deleted.' format.html { redirect_to(:action => 'list') } format.xml { head :ok } end end
end
LIST VIEW <% @page_title = 'Current Users' -%>
<%= content_tag('p', link_to('« Back to Menu', :controller => 'staff', :action => 'menu')) %>
<div class='userlist_left'> <%= render(:partial => 'listing') -%> </div> <div class= 'userlist_right'> Please select a user on the left or create a new user. <%= link_to('New user', :action => 'manage') -%> </div>
MANAGE VIEW <% @page_title = 'Current Users' -%>
<%= content_tag('p', link_to('« Back to Menu', :controller => 'staff', :action => 'menu')) %>
<div class='userlist_left'> <%= render(:partial => 'listing') -%> </div> <div class= 'userlist_right'> <% if params[:id].blank? %> <h2>New user</h2>
<% form_for(@user) do |f| -%> <%= render(:partial => 'form') -%> <p class= 'user_submit'><%= submit_tag "Create" -%></p> <% end -%> <% else -%> <h2>Editing user</h2>
<% form_for(@user) do |f| -%> <%= render(:partial => 'form')%> <p class= 'user_submit'><%= submit_tag "Update" -%></p> <% end -%>
<p class= 'user_submit'><%= link_to('Delete User', { :action => 'destroy', :id => @user }, :confirm => 'Are you sure you want to permanently delete this user?', :method => :delete) -%>
<% end -%>
<%= link_to('Cancel', :action => 'list') %></p>
</div>
_LISTING PARTIAL <div class='userlist_listing'> <table> <tr> <th>First Name</th> <th>Last Name</th> <th>Username</th> <th>User Level</th> </tr> <% for user in @users -%> <tr class='<%= cycle('row1', 'row2')%>'> <td><%= h(user.first_name) -%></td> <td><%= h(user.last_name) -%></td> <td><%= h(user.username) -%></td> <td><%= h(user.user_level) -%></td> <td><%= link_to('Edit', :action => 'manage', :id => user) -%></
</tr> <% end %> </table> </div><br/>
_FORM PARTIAL <%= error_messages_for(:user) -%>
<table> <tr> <th>Username</td> <td><%= text_field(:user, :username) -%></td> </tr> <tr> <th>Hashed Password</th> <td><%= text_field(:user, :hashed_password) -%></td> </tr> <tr> <th>First Name</th> <td><%= text_field(:user, :first_name) -%></td> </tr> <tr> <th>Last Name</th> <td><%= text_field(:user, :last_name) -%></td> </tr> <tr> <th>Email</th> <td><%= text_field(:user, :email) -%></td> </tr>
<tr> <th>Display Name</th> <td><%= text_field(:user, :display_name) -%></td> </tr>
<tr> <th>User Level</th> <td><%= select(:user, :user_level, [0,1,2,3,4,9]) -%></td> </tr> </table>