Jump to content

The ultimate community for Ruby on Rails developers.


Photo

errors.on in Rails 4

rails 4 model

  • Please log in to reply
3 replies to this topic

#1 patrickmaciel

patrickmaciel

    Passenger

  • Members
  • 4 posts

Posted 23 September 2013 - 02:22 AM

Hello!

I'm starting with RoR today, but I buy a RoR 3.2 book, and my installation on Ubuntu is Rails 4 and Ruby 2.0.

 

Anyway, in book I have this code:

article.errors.on(:title)

But, not works in Rails 4.

2.0.0-p247 :074 > article.errors.on(:title)
NoMethodError: undefined method `on' for #<ActiveModel::Errors:0x0000000427e238>
	from (irb):74
	from /home/patrick/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
	from /home/patrick/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
	from /home/patrick/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'
2.0.0-p247 :075 > 

What is equivalent

on( )

method?

 

Thanks!

 



#2 Ohm

Ohm

    Guard

  • Members
  • 184 posts
  • LocationCopenhagen

Posted 23 September 2013 - 05:18 AM   Best Answer

I might be wrong, but I believe errors behaves just like a hash. You should be able do

article.errors[:title]

  • patrickmaciel likes this

Blog: http://ohm.sh | Twitter: madsohm


#3 katafrakt

katafrakt

    Signalman

  • Members
  • 16 posts
  • LocationKraków, PL

Posted 23 September 2013 - 07:16 AM

on is deprecated since 3.0.0. (http://apidock.com/r...ource/Errors/on) What kind of book it is that it uses is in 3.2?

 

Also, if you have book about 3.2, use 3.2. There are too many differences between these versions to just skip them if you are new to rails.


  • patrickmaciel likes this

#4 patrickmaciel

patrickmaciel

    Passenger

  • Members
  • 4 posts

Posted 23 September 2013 - 10:40 PM

on is deprecated since 3.0.0. (http://apidock.com/r...ource/Errors/on) What kind of book it is that it uses is in 3.2?

 

Also, if you have book about 3.2, use 3.2. There are too many differences between these versions to just skip them if you are new to rails.

 

I think my book is very crazy: Beginning Rails 3 (but in book content, say "it's for 3.2 version").

 

Anyway, thanks :)

 

I think maybe downgrade is the better option for now.







Also tagged with one or more of these keywords: rails 4, model

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users