Validates* give me problems


#1

Hi All,

I’m newbie to this tool and following some tutorials I’ve came across
with this problem when configuring my webpage:

In Debian/testing, ruby1.8, rails1.1

I create my audio application which connects to a database (mysql) named
audio with tables:
articulos(id,titulo,descripcion,created_on,categoria_id) and
categorias(id,titulo)

after creating and modifying the corresponding files (database.yml,
.htaccess) I do:

ruby script/generate scaffold articulo
ruby script/generate scaffold categoria

I’ve modified my apache2’s config files in order to access my
application through this server, so I write: http://audio and everything
goes fine. I’m able to enter articulos and categorias, list, edit, show,
and delete them without problems. But when I introduce in:

~app/models/categoria.rb

a line with: validates_uniqueness_of :categoria, :message => “ya existe”

I get in my browser when creating a new categoria item:

NoMethodError in Categorias#create

undefined method `categoria’ for #Categoria:0x40a606cc

RAILS_ROOT: /var/www/audio/public/…/config/…
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in
method_missing' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:invalidates_each’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in
validates_each' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:794:inrun_validations’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:788:in
run_validations' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:752:invalid_without_callbacks’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/callbacks.rb:306:in
valid?' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:723:insave_without_transactions’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:126:in
save' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:51:intransaction’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:91:in
transaction' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:118:intransaction’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:126:in
save' #{RAILS_ROOT}/app/controllers/categorias_controller.rb:25:increate’

#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in
method_missing' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:invalidates_each’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in
validates_each' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:794:inrun_validations’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:788:in
run_validations' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:752:invalid_without_callbacks’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/callbacks.rb:306:in
valid?' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:723:insave_without_transactions’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:126:in
save' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:51:intransaction’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:91:in
transaction' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:118:intransaction’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:126:in
save' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:908:inperform_action_without_filters’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:355:in
perform_action_without_benchmark' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:inperform_action_without_rescue’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in
perform_action' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:379:inprocess_without_filters’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:364:in
process_without_session_management_support' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:117:inprocess’
#{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:38:in dispatch' #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:150:inprocess_request’
#{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:54:in process!' /usr/lib/ruby/1.8/fcgi.rb:600:ineach_cgi’
/usr/lib/ruby/1.8/fcgi.rb:597:in each_cgi' #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:53:inprocess!’
#{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:23:in `process!’
/var/www/audio/public/dispatch.fcgi:26

#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in
method_missing' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:invalidates_each’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in
validates_each' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:794:inrun_validations’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:788:in
run_validations' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:752:invalid_without_callbacks’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/callbacks.rb:306:in
valid?' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:723:insave_without_transactions’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:126:in
save' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:51:intransaction’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:91:in
transaction' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:118:intransaction’
#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/transactions.rb:126:in
save' #{RAILS_ROOT}/app/controllers/categorias_controller.rb:25:increate’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:908:in
perform_action_without_filters' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:355:inperform_action_without_benchmark’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:82:inperform_action’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:379:in
process_without_filters' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:364:inprocess_without_session_management_support’
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:117:in
process' #{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:38:indispatch’
#{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:150:in
process_request' #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:54:inprocess!’
/usr/lib/ruby/1.8/fcgi.rb:600:in each_cgi' /usr/lib/ruby/1.8/fcgi.rb:597:ineach_cgi’
#{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:53:in process!' #{RAILS_ROOT}/vendor/rails/railties/lib/fcgi_handler.rb:23:inprocess!’
/var/www/audio/public/dispatch.fcgi:26

Request

Parameters: {“categoria”=>{“titulo”=>“as”}, “commit”=>“Create”}

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}

Any ideas?

Cheers,

Antonio


#2

antonio rv wrote:

I’ve modified my apache2’s config files in order to access my
application through this server, so I write: http://audio and everything
goes fine. I’m able to enter articulos and categorias, list, edit, show,
and delete them without problems. But when I introduce in:

~app/models/categoria.rb

a line with: validates_uniqueness_of :categoria, :message => “ya existe”

I get in my browser when creating a new categoria item:

NoMethodError in Categorias#create

I suspect that should be validate_uniqueness_of :titulos, :message =>
“ya existe”

You’re telling the category to validate the uniqueness of the title when
it’s created.

Alan


#3

Alan F. escribió:

You’re telling the category to validate the uniqueness of the title when
it’s created.

Alan

Dear Alan,

Many, many thanks!! Now it works!

Best regards!

Antonio