8

I'm trying to figure out how to use dependent-fields-rails gem with my Rails 4 app.

I'm lost.

I have included underscore.js in my vendor javascripts folder and updated my application.js to include (right at the bottom, just above require tree):

//= require underscore
//= require dependent-fields


$(document).ready(function() {
    DependentFields.bind()
});

In my simple form, I have:

<%= f.input :has_milestones, as: :boolean, boolean_style: :inline, :label => 'Any decision points?', id: 'check_project_milestones' %>

<%= content_tag :div, class: 'js-dependent-fields', data: {'checkbox-id': 'check_project_milestones', 'checkbox-value': 'true' } do %>        

  <div class="intpol2">
    Milestones
  </div>

  <%= f.simple_fields_for :milestones do |f| %>
    <%= render 'milestones/milestone_fields', f: f %>
  <% end %>
<% end %>

However, when I restart the server and render the form, the first question which has the div id, is shown (which the check box unticked) and the content inside the content tag is also showing. I want it to be hidden until the checkbox is checked.

I found a tutorial on driftingruby.com which shows how to set this up. The only thing I can guess is that maybe turbo links is required to make this work?? I have it disabled because I use olark.

When I inspect the console for errors, I can see this one, which appears to be relevant:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (underscore-min.map, line 0)

I should also add that I tried everything suggested in answer to my earlier question on this problem, but wasn't able to find a solution: Rails 4 - JS for dependent fields with simple form

Can anyone see what I've done wrong?

6
  • stackoverflow.com/questions/18393052/… Commented Apr 23, 2016 at 6:12
  • I don't have a line in my underscore.js that has "sourceMapping" in it Commented Apr 23, 2016 at 6:16
  • The error is very clear, something is referencing the map file whether you like it or not. Commented Apr 23, 2016 at 9:12
  • but i don't seem to have that file in my project Commented Apr 23, 2016 at 11:17
  • Do you have the app on github? Commented Apr 23, 2016 at 11:18

2 Answers 2

1

What you're experiencing is source mapping. This allows you to debug with readable code in your browser's developer tools when working with minified JS files.

The minified version of Underscore has this line at the end of the file:

//# sourceMappingURL=underscore-min.map

Your browser's developers tools will try to download underscore-min.map when encountering this line.

If you want to get rid of the error, either:

  1. Remove that line from underscore-min.js
  2. Add underscore-min.map and underscore.js to your project.
Sign up to request clarification or add additional context in comments.

8 Comments

I didn't add the production version (minified) of underscore.js to my javascript folder. I added the dev version, which I understand has not been minifed. Do you think your answer is relevant given I don't have the min file in my project?
Do I need to save underscore-min.map with a .js extension? Presumably I also need to add it to application.js?
I tried adding underscore-min.map file to my vendor/javascripts and then precompiling assets. I tried again, but the js dependent fields still doesnt work
When I try requiring that file to app/assets/javascripts/application.js, I get an error that says: couldn't find file 'underscore-min.map' with type 'application/javascript'
install gem 'underscore-rails' and then bundle it and restart the rails server.
|
0

Did you also added the min maps on vendor?

The source maps are used for javascript debugging on your browser

You can download it on underscore js as well: where is written

source map

or: http://underscorejs.org/underscore-min.map

See also: Rails Assets - 404 with .map extension

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.