Y
Y
Yauheni Dakuka2015-08-08 23:08:42
Ruby on Rails
Yauheni Dakuka, 2015-08-08 23:08:42

How to change routing effect on coffeescript?

In the config/routes.rb file:

resource :quizzes do
  resource :questions
end

Also in assets / javascripts:
quizzes.coffee
question.coffee
? How to avoid it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
TyzhSysAdmin, 2015-08-08
@ydakuka

Look at the "page sources", you will see explicit loading of all your scripts there, because you have such an instruction in application.js //= require_tree . which, roughly speaking, means "insert everything in /assets/javascripts/ into application.html.erb" because in turn you have the following line in application.html.erb
Alternatively, you can remove //= require_tree . from application.js and explicitly specify which scripts need to be loaded by default and for individual pages do this
in /views/layouts/application.html.erb

<head>
  ...
  <%= yield :header %>
  ...
</head>

in /views/quizzes/your_views_name.html.erb
<% content_for :header do %>
  <%= javascript_include_tag 'quizzes' %>  
<% end %>

Then, when using this view, a tag connecting your JS (coffee) script will always be inserted into the HEAD section.
I do not pretend to the correctness of the decision, senior comrades will catch up and confirm or reject the decision :)

P
Pavel Kononenko, 2015-08-08
@premas

Use content_for

V
Viktor Vsk, 2015-08-08
@viktorvsk

Because you have a line in application.js
or separately

//= require quizzes
//= require questions

Learn to open the page source code and understand what an asset pipeline is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question