When my params for my observe_field are empty or 0 I get the ''template missing'' error. I''m trying to emulate the ''user name is valid/not valid'' feature that many apps have when signing up. As long as the params is greater than zero everything is fine. def already_taken if params[:user].strip.length > 0 user = User.find_by_name(params[:user]) if user render :update do |page| page[:already_taken].replace_html "Already taken!" page[:already_taken].set_style :color => ''red'' end elsif user == nil render :update do |page| page[:already_taken].replace_html "Available!" page[:already_taken].set_style :color => ''green'' end end end end There must be an easier way to do this because it is such a common feature. Thanks for any help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2007-Apr-09 19:30 UTC
Re: How to get around observe_field ''template missing'' error?
On 09 Apr 2007, at 21:17, jko170 wrote:> When my params for my observe_field are empty or 0 I get the ''template > missing'' error. I''m trying to emulate the ''user name is valid/not > valid'' feature that many apps have when signing up. As long as the > params is greater than zero everything is fine. > > def already_taken > if params[:user].strip.length > 0 > user = User.find_by_name(params[:user]) > if user > render :update do |page| > page[:already_taken].replace_html "Already taken!" > page[:already_taken].set_style :color => ''red'' > end > elsif user == nil > render :update do |page| > page[:already_taken].replace_html "Available!" > page[:already_taken].set_style :color => ''green'' > end > end > end > end > > There must be an easier way to do this because it is such a common > feature. Thanks for any help!Well, you would be better off using javascript itself instead of the rails helper and check for the value being empty clientside and only query the server if a certain number of characters is entered, but if you want to stick with the rails helpers, you should add: def already_taken if params[:user].strip.length > 0 # do your thing else render :nothing => true end end Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jko170
2007-Apr-09 20:37 UTC
Re: How to get around observe_field ''template missing'' error?
Thanks a lot Peter! I''m sure there''s a better way to do my entire project, but I guess this is fine for now (plenty of time to learn more and refactor after project is up). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-11 14:43 UTC
Re: How to get around observe_field ''template missing'' error?
I would recommend adding something like :condition => ''value.length > 0'' to your observe form. Also you can replace .strip.length > 0 with .blank? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---