Forum: Ruby on Rails Rails form error message oddness...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
James W. (Guest)
on 2006-04-10 16:16
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])

    if &&
      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:

<div id="newClient">

<%= 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 %>

  <div id="clientList">

    <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 topic is locked and can not be replied to.