errors.on equilvalent on Rails 4

17 views
Skip to first unread message

Patrick Maciel Campos

unread,
Sep 22, 2013, 10:23:22 PM9/22/13
to rubyonra...@googlegroups.com

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!

Jordon Bedwell

unread,
Sep 23, 2013, 9:19:18 AM9/23/13
to rubyonra...@googlegroups.com
On Sun, Sep 22, 2013 at 9:23 PM, Patrick Maciel Campos
<patrickma...@gmail.com> wrote:
> 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.

On was deprecated and removed in Rails 4... I'm surprised that author
would have even left something like that in a Rail 3.2 guide since it
would have hindered future development... either way, to address your
issue now you simply do `errors[:title]` to pull your error. If you
are looking for it to return true or false then you should do
`errors[:title].present?` or you can use `blank?` if you please.
Reply all
Reply to author
Forward
0 new messages