As you may know, this gem initializer file has code, which you need to uncomment to show validation error inline to every form field: # Uncomment the following block if you want each input field to have the validation messages attached. ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| unless html_tag =~ /^<label/ %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe else %{<div class="field_with_errors">#{html_tag}</div>}.html_safe end end I uncommented this code, but for one special model I want to display errors as usual. I tried to refactor default code ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if "#{instance.send(:tag_id)}"!="answer_user_answer" #that''s label for this model unless html_tag =~ /^<label/ %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe else %{<div class="field_with_errors">#{html_tag}</div>}.html_safe end end end but that doesn''t work. Thanks in advance for help -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zqEA8H_EPuQJ. For more options, visit https://groups.google.com/groups/opt_out.
Gintautas Šimkus
2013-Apr-02 03:28 UTC
Re: How to set exception in client side validation gem
Try using instance.instace_of?(YourModelName) as your condition to make an exception in case of YourModelName 2013/4/2 Barry <burmanz-JGs/UdohzUI@public.gmane.org>> As you may know, this gem initializer file has code, which you need to > uncomment to show validation error inline to every form field: > > # Uncomment the following block if you want each input field to have the > validation messages attached. > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > > unless html_tag =~ /^<label/ > %{<div class="field_with_errors">#{html_tag}<label > for="#{instance.send(:tag_id)}" > class="message">#{instance.error_message.first}</label></div>}.html_safe > else > %{<div class="field_with_errors">#{html_tag}</div>}.html_safe > end > end > > I uncommented this code, but for one special model I want to display > errors as usual. I tried to refactor default code > > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > > if "#{instance.send(:tag_id)}"!="answer_user_answer" #that''s label for > this model > unless html_tag =~ /^<label/ > %{<div class="field_with_errors">#{html_tag}<label > for="#{instance.send(:tag_id)}" > class="message">#{instance.error_message.first}</label></div>}.html_safe > else > %{<div class="field_with_errors">#{html_tag}</div>}.html_safe > end > end > end > > but that doesn''t work. > > Thanks in advance for help > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/zqEA8H_EPuQJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- Pagarbiai, Gintautas -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
thanks for advice, but that doesn''t work вторник, 2 апреля 2013 г., 1:07:14 UTC+4 пользователь Barry написал:> > As you may know, this gem initializer file has code, which you need to > uncomment to show validation error inline to every form field: > > # Uncomment the following block if you want each input field to have the > validation messages attached. > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > > unless html_tag =~ /^<label/ > %{<div class="field_with_errors">#{html_tag}<label > for="#{instance.send(:tag_id)}" > class="message">#{instance.error_message.first}</label></div>}.html_safe > else > %{<div class="field_with_errors">#{html_tag}</div>}.html_safe > end > end > > I uncommented this code, but for one special model I want to display > errors as usual. I tried to refactor default code > > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > > if "#{instance.send(:tag_id)}"!="answer_user_answer" #that''s label for > this model > unless html_tag =~ /^<label/ > %{<div class="field_with_errors">#{html_tag}<label > for="#{instance.send(:tag_id)}" > class="message">#{instance.error_message.first}</label></div>}.html_safe > else > %{<div class="field_with_errors">#{html_tag}</div>}.html_safe > end > end > end > > but that doesn''t work. > > Thanks in advance for help > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KYZqDTrc3goJ. For more options, visit https://groups.google.com/groups/opt_out.
Ok guys, finally gem caused several issues, which was hard to debug, so finally I just set up my own jquery validation, and it was no so hard as I imagined. Like this solution, not always gems are suitable, and it was good practice) вторник, 2 апреля 2013 г., 1:07:14 UTC+4 пользователь Barry написал:> > As you may know, this gem initializer file has code, which you need to > uncomment to show validation error inline to every form field: > > # Uncomment the following block if you want each input field to have the > validation messages attached. > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > > unless html_tag =~ /^<label/ > %{<div class="field_with_errors">#{html_tag}<label > for="#{instance.send(:tag_id)}" > class="message">#{instance.error_message.first}</label></div>}.html_safe > else > %{<div class="field_with_errors">#{html_tag}</div>}.html_safe > end > end > > I uncommented this code, but for one special model I want to display > errors as usual. I tried to refactor default code > > ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| > > if "#{instance.send(:tag_id)}"!="answer_user_answer" #that''s label for > this model > unless html_tag =~ /^<label/ > %{<div class="field_with_errors">#{html_tag}<label > for="#{instance.send(:tag_id)}" > class="message">#{instance.error_message.first}</label></div>}.html_safe > else > %{<div class="field_with_errors">#{html_tag}</div>}.html_safe > end > end > end > > but that doesn''t work. > > Thanks in advance for help > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vJ3wn4YJdO8J. For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-Apr-03 23:39 UTC
Re: Re: How to set exception in client side validation gem
On Tue, Apr 2, 2013 at 6:31 PM, Barry <burmanz-JGs/UdohzUI@public.gmane.org> wrote:> Ok guys, finally gem caused several issues, which was hard to debug, so > finally I just set up my own jquery validation, and it was no so hard as I > imagined. Like this solution, not always gems are suitable, and it was good > practice)Now that you have a solution in hand that *does* work for you, refactor it into it''s own gem so you can reuse it, and push it up. Maybe you''ll make someone else''s day better! :) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.