Search code examples
ruby-on-rails-3knockout.jsformtastic

How to data bind a field in formtastic page for knockoutjs


Im trying to implement knockoutjs in my formtastic page. How can i bind data to a scaffold edformtastic erb page.

This is how i tried it. But didn't work

 <%= f.input :name, :data=>{:bind=>'value: name'} %>

my javascript

this.name = ko.observable("Bert");

Solution

  • I don't know how knockoutjs works, but for the formtastic part, you should do this:

    <%= f.input :name, :input_html => {"data-bind" => "value: name" } %>
    

    I'm not the one who voted down. ;-) (I'll vote up).