Rails form error message oddness

To get error messages for my form to show up I have to repeat myself in
the controller so that the render of the view including error messages
show up.

My Controller:

class ClientsController < ApplicationController

#---- index --------------------------------
def index
render :action => ‘list’

#---- list --------------------------------
def list
@client_pages, @clients = paginate(:clients, :order_by => ‘name’)

#---- new client --------------------------------
def new
#raise params.inspect
@client = Client.new(@params[:client])

if request.post? && @client.save
  flash['notice'] = 'Client created successfully'
  redirect_to :action => 'list'
  @client_pages, @clients = paginate(:clients, :order_by => 'name')
  render :action => 'list'



I am having to repeat the line: @client_pages, @clients =
paginate(:clients, :order_by => ‘name’) just before the render :action
=> ‘list’. Surely rendering the action would keep all of the variables
like @clients.

Is this the correct way to achieve this or am I making things really
complicated? Thanks for your help.

My view is listed here to help:

My View:

<%= form_tag :action => ‘new’ %>

<div class="basicForm">
 <h3>Add a new Client</h3>
<%= error_messages_for 'client' %>

  <dt><label for="client_name">Client Name:</label></dt>
  <dd><%= text_field "client", "name", :size => 40 %></dd>

  <dt><label for="client_reference">Client Reference:</label></dt>
  <dd><%= text_field "client", "reference", :size => 40 %></dd>

<%= submit_tag “post” %>


<%= end_form_tag %>

<h3>Current Clients </h3>
<p>A list of the current active clients.</p>

<%= start_form_tag :action=> "new" %>
  <% for client in @clients -%>
    <%= render(:partial => "client_list", :object => client) %>
  <% end -%>

<%= end_form_tag %>

<div id="pageNavigation" class="clear">
  <%= pagination_links(@client_pages) %>

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