Ruby on Rails
Wednesday, December 24, 2014
2014-12-24 11:27 GMT-02:00 Vivek Sampara <ravensnowbird@gmail.com>:
Hi Anjos,Which is the class that is not ActiveRecord descendent ? Im assuming Taxes::Premisefinderdefine an errors class this wayclass Errorattr_accessor :errorsdef initialize@errors = {}enddef add(key, message)self.errors[key] = messageendendclass Cardef errors@errors ||= Error.newendend@car = Car.new@car.errors.add(:name, "Invalid")And you can define valid? method and add errors accordingly.Its not perfect but can be a good starting point.--On Wed, Dec 24, 2014 at 5:08 PM, Cezinha Anjos <cezinha.anjos@gmail.com> wrote:--Hi everyone! Are you ok? I hope yes...I'm working on a class whose its responsibility is calculate Brazilian taxes.Its use is so and so like this:invoice_product = InvoiceProduct.new(filtered_params)operationkind = Operationkind.find(params[:operationkind_id])recipient = Person.find(params[:recipient_id])finder = Taxes::Premisefinder.newfinder.find(current_user.licenciated,recipient.city.uf,operationkind,invoice_product.product.taxgroup,invoice_product)render json: invoice_product, status: :createdIt's used in a controller to respond as json in a rest API. It's not a ActiveRecord descendent class.My doubt is: what is the best way to collect the possible errors generated from Taxes::Premisefinder?Should I do Taxes::Premisefinder generates exceptions and catch them on the controller?Should I use similar strategy of ActiveRecord using Errrors class?In this case, what's the Rails way to work?Thanks!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f5546b00-c752-476a-86cc-3e19621152ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj-f6v1ySsT_1v1okX07V_z7PvZBNQEq4cv5c7oe3JFCtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
César Luiz dos Anjos Júnior
Diretor
(48) 3263-7137
http://www.asseinfo.com.br
"A curiosidade é um dos maiores sinais de vitalidade de um profissional."
Jim Collins
"Keep learning like a crazy..."
Uncle Bob
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACDeCptJ%3D00mGjW8MRw2j%3DtTh-5w9vFf0TwBVC_DPevus8chsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment