ruby 2.1.2, rails 4.1.1
I have an "Order" model, when creating a new order"/orders/new" the order form has an "add row" link that dynamically adds a new row to the form. It all works(almost).
If I visit the page by typing "/orders/new" directly in the address bar it all works perfectly. But if I visit the page by following the "Create new order" link as users will tend to do, the "add row" link doesn't work and I get the following JavaScript error in the console...
TypeError: currentState is null
currentStateUrl = new ComponentUrl(currentState.url);
If I remove "//= require turbolinks" line from my "application.js" it works ok, so issue must be turbolinks related but not sure how to go about solving?
The way the "add_row" link works is I have the following on "application_helper.rb"
def link_to_add_fields(name, f, association)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render(association.to_s.singularize + "_fields", f: builder)
end
link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
end
Worst case scenario can turbolinks be disabled for particular pages?
Ah sorted, I see you can add "data-no-turbolink => true" to my "Create new order" link.
<%= link_to "Create new order", new_order_path, 'data-no-turbolink' => true %>