Validation error handling on related models

James Byrne wrote:

<%= error_messages_for :client %>

<% form_for(@client) do |cu| %>   <% fields_for @entity do |en| %>     Name <%= en.text_field :entity_name %>     <br />Legal name <%= en.text_field :entity_legal_name %>     <br />Legal form <%= en.text_field :entity_legal_form %>   <% end %>

X-POSTED Rails Forum

Name <%= en.text_field :entity_name %>

should be something like:

Name <%= en.text_field :name %>

hth

p.s. a great way to debug this is to stick a debugger statement at the top of your controller method, gem install ruby-debug and then start your mongrel server like this: script/server webrick -u

or if you don't have mongrel.. What.. you don't have mongrel???!!!!

hth

ilan

Ilan Berci wrote:

Name <%= en.text_field :entity_name %>

should be something like:

Name <%= en.text_field :name %>

I do not think so. The attribute is indeed entity_name for in the migration I have:

class CreateEntities < ActiveRecord::Migration

  def self.up     create_table :entities do |t|

      t.string :entity_name, :null => false,                 :limit => 30       t.string :entity_legal_name, :null => false,                 :limit => 120       t.string :entity_legal_form, :null => false,                 :limit => 4

James Byrne wrote:

I do not think so. The attribute is indeed entity_name for in the migration I have:

James Byrne wrote:

I do not think so. The attribute is indeed entity_name for in the migration I have:

Whoops.. you are right, my bad! I still believe however that the data is not coming into your controllers correctly so the missing fields trip your validators.

I would just debug it as I suggested above and the error will come screaming out at you..

ilan

Ilan Berci wrote:

James Byrne wrote:

I do not think so. The attribute is indeed entity_name for in the migration I have:

James Byrne wrote:

I do not think so. The attribute is indeed entity_name for in the migration I have:

Whoops.. you are right, my bad! I still believe however that the data is not coming into your controllers correctly so the missing fields trip your validators.

Well, perhaps I did not make myself clear to begin with. I am testing the validators and so the data is indeed missing. The problem I am having here is that the flash notice is not displaying on the edit page as I expect.

This code is at a very rudimentary stage and there are a number of intricate dependencies that I have yet to code. So I am taking care that all the straight-forward error handling is working as I expect and that my assumptions are checked against reality at an early stage.

Ilan Berci wrote:

p.s. a great way to debug this is to stick a debugger statement at the top of your controller method, gem install ruby-debug and then start your mongrel server like this: script/server webrick -u

Thanks for the heads up on this. I have installed it and found a decent write up on it at:

http://blog.nanorails.com/articles/2006/07/14/a-better-rails-debugger-ruby-debug

or if you don't have mongrel.. What.. you don't have mongrel???!!!!

Nope.

I was poking around in the controllers/application.rb and removed (commented) some code thus:

  # def rescue_action(exception)   # if exception.class.to_s == 'ActionController::RoutingError'   # logger.error "404 #{exception}"   # @pageTitle = 'Not found'   # redirect_to '/404.html'   # # render :template => 'frontpage/render_404', :layout => 'standard',   # # :status => '404 Not found'   # # unless ENV['RAILS_ENV'] == 'production' or request.env['REQUEST_URI'] == '/test_404'   # # bb_log "Dumping call stack at 404: #{request.env['REQUEST_URI']}\n"+caller.join("\n ")   # # end   # else   # log_error(exception)