Posts Tagged ‘ActionView’

Good-bye Tedium, Hello Field_Set_Forms

April 12th, 2009

I just published a new plug-in on GitHub (http://github.com/ncancelliere/field_set_forms) which takes the boring chore out of developing web forms.

I don’t know about you but I hate how tedious forms can be. The idea of just providing a field type and linking it to your ActiveRecord attribute is nothing new. There are a dozen different form builders out there. I haven’t seen any that would do everything I wanted though, so I made my own.

Another thing that would always get me is remembering whether or not to mark a field as required. Well this plug-in takes care of that to. It uses ActiveRecord reflection to determine if the field is required, and will automatically put a star next to it if it is. There are some other label generation features as well.

I hope you enjoy it.

Rails Flash Notices with Fade

November 11th, 2008

Something I normally find in the view code – I’ve written a snippet that takes care of in the application helper.  The method handles a flash with multiple messages in it (I don’t know when/how that’d ever come about – but if it did it’ll handle it just find displaying both messages).


def show_flash_message(options={})
  html = content_tag(:div, flash.collect{ |key,msg| content_tag(:div, msg, :class => key) },
:id => 'flash-message')
  if options.key?(:fade)
    html << content_tag(:script,"setTimeout("new Effect.Fade('flash-message');",#{options[:fade]*1000})",
:type => 'text/javascript')
  end
  html
end

Then in your view simply refer to:

     <%= show_flash_message(:fade => 4) %>

If you want the fade option be sure to have the javascript_include_tag :defaults on your page – the fade effect uses prototype.

Enjoy.