Joel Nylund
2008-Jan-31 16:14 UTC
[Facebooker-talk] presenting validation errors via fbml?
Hi Facebookers, Is there a helper or suggested approach for presenting validation errors on an fbml form? Something to translate rails error markup to fbml:error markup? thanks Joel
Shane Vitarana
2008-Jan-31 19:30 UTC
[Facebooker-talk] presenting validation errors via fbml?
Joel- Just wrap your flash[:error] inside an fb_error helper. Or put <%= facebook_messages %> in your layout. Shane On Jan 31, 2008 10:14 AM, Joel Nylund <jnylund at yahoo.com> wrote:> Hi Facebookers, > > Is there a helper or suggested approach for presenting validation > errors on an fbml form? > > Something to translate rails error markup to fbml:error markup? > > thanks > Joel > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk >-- http://myfitbuddy.com | http://shanesbrain.net | http://crimsonjet.com
Joel Nylund
2008-Feb-05 20:04 UTC
[Facebooker-talk] presenting validation errors via fbml?
Hi, I tend to use error_messages_for so I wrote a helper: fbml_error_messages_for, that puts the right facebook tags in there & formats them somewhat nicely. Let me know if you think others would like this and I can create some testcases so you can add it, otherwise I will just leave in my helper. Note, the rails helper changed form 1.2 to 2, I hacked up the 1.2 one to get this, I think it will work just fine on 2 but not sure. thanks Joel def fbml_error_messages_for(*params) logger.debug "facehelper version being called" options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {} objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact count = objects.inject(0) {|sum, object| sum + object.errors.count } unless count.zero? html = {} [:id, :class].each do |key| if options.include?(key) value = options[key] html[key] = value unless value.blank? else html[key] = ''errorExplanation'' end end header_message = "#{pluralize(count, ''error'')} prohibited this #{(options[:object_name] || params.first).to_s.gsub(''_'', '' '')} from being saved" error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } } content_tag(''fb:error'', content_tag(''fb:message'', header_message) << content_tag(:p, ''There were problems with the following fields:'') << content_tag(:ul, error_messages, :style => ''font-size:12px;''), html ) else '''' end end On Jan 31, 2008, at 2:30 PM, Shane Vitarana wrote:> Joel- Just wrap your flash[:error] inside an fb_error helper. Or put > <%= facebook_messages %> in your layout. > > Shane > > On Jan 31, 2008 10:14 AM, Joel Nylund <jnylund at yahoo.com> wrote: >> Hi Facebookers, >> >> Is there a helper or suggested approach for presenting validation >> errors on an fbml form? >> >> Something to translate rails error markup to fbml:error markup? >> >> thanks >> Joel >> >> _______________________________________________ >> Facebooker-talk mailing list >> Facebooker-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/facebooker-talk >> > > > > -- > http://myfitbuddy.com | http://shanesbrain.net | http://crimsonjet.com
Shane Vitarana
2008-Feb-05 21:15 UTC
[Facebooker-talk] presenting validation errors via fbml?
Joel- This is great. Can you re-use the existing fb status helpers instead of the custom content tags? If you include a test, and send it as a patch to Rubyforge <http://rubyforge.org/projects/facebooker/>, I''ll add it in with attribution. Thanks, Shane On Feb 5, 2008 2:04 PM, Joel Nylund <jnylund at yahoo.com> wrote:> Hi, > > I tend to use > > error_messages_for > > so I wrote a helper: > > fbml_error_messages_for, that puts the right facebook tags in there & > formats them somewhat nicely. > > Let me know if you think others would like this and I can create some > testcases so you can add it, otherwise I will just leave in my helper. > > Note, the rails helper changed form 1.2 to 2, I hacked up the 1.2 one > to get this, I think it will work just fine on 2 but not sure. > > thanks > Joel > > > > def fbml_error_messages_for(*params) > logger.debug "facehelper version being called" > options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {} > objects = params.collect {|object_name| > instance_variable_get("@#{object_name}") }.compact > count = objects.inject(0) {|sum, object| sum + > object.errors.count } > unless count.zero? > html = {} > [:id, :class].each do |key| > if options.include?(key) > value = options[key] > html[key] = value unless value.blank? > else > html[key] = ''errorExplanation'' > end > end > header_message = "#{pluralize(count, ''error'')} prohibited this > #{(options[:object_name] || params.first).to_s.gsub(''_'', '' '')} from > being saved" > error_messages = objects.map {|object| > object.errors.full_messages.map {|msg| content_tag(:li, msg) } } > content_tag(''fb:error'', > content_tag(''fb:message'', header_message) << > content_tag(:p, ''There were problems with the following > fields:'') << > content_tag(:ul, error_messages, :style => ''font-size:12px;''), > html > ) > else > '''' > end > end > > > > > On Jan 31, 2008, at 2:30 PM, Shane Vitarana wrote: > > > Joel- Just wrap your flash[:error] inside an fb_error helper. Or put > > <%= facebook_messages %> in your layout. > > > > Shane > > > > On Jan 31, 2008 10:14 AM, Joel Nylund <jnylund at yahoo.com> wrote: > >> Hi Facebookers, > >> > >> Is there a helper or suggested approach for presenting validation > >> errors on an fbml form? > >> > >> Something to translate rails error markup to fbml:error markup? > >> > >> thanks > >> Joel > >> > >> _______________________________________________ > >> Facebooker-talk mailing list > >> Facebooker-talk at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/facebooker-talk > >> > > > > > > > > -- > > http://myfitbuddy.com | http://shanesbrain.net | http://crimsonjet.com > >-- http://myfitbuddy.com | http://shanesbrain.net | http://crimsonjet.com