simple_form with AngularJS

Maybe I’ll stop monkeying with code, but here’s a time saver.  Couldn’t find a great solution to add ng-model’s to my bootstrap forms to bind AngularJS and certainly this doesn’t take the cake, but it does add my model names for my ng-models with simple_form.  Comment if you find issues in your code.  (Note: You will want to change the wrapper name here to ~namespace it to your wrapper). I did this to avoid conflicts on non-angular forms.

 module SimpleForm
   module Inputs
     class Base
       def input_html_options
         if @builder.options[:wrapper] == :bootstrap_angular
@input_html_options.reverse_merge!({ "ng-model" => "#{@builder.lookup_model_names.join(".")}.#{self.attribute_name}" })
About the Author: JeffAncel
A passionate web developer in St. Louis. Living on the edge with Rails, HTML5, CSS3 and any interesting libraries around. I love to spend time with the family, cook, develop web applications and play with our dragons. When I have nothing else to do, I socialize via twitter (@jancel) and facebook.

Leave a reply

© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top