<i id='OsLCW'><tr id='OsLCW'><dt id='OsLCW'><q id='OsLCW'><span id='OsLCW'><b id='OsLCW'><form id='OsLCW'><ins id='OsLCW'></ins><ul id='OsLCW'></ul><sub id='OsLCW'></sub></form><legend id='OsLCW'></legend><bdo id='OsLCW'><pre id='OsLCW'><center id='OsLCW'></center></pre></bdo></b><th id='OsLCW'></th></span></q></dt></tr></i><div id='OsLCW'><tfoot id='OsLCW'></tfoot><dl id='OsLCW'><fieldset id='OsLCW'></fieldset></dl></div>

      <small id='OsLCW'></small><noframes id='OsLCW'>

      <tfoot id='OsLCW'></tfoot>
          <bdo id='OsLCW'></bdo><ul id='OsLCW'></ul>

      1. <legend id='OsLCW'><style id='OsLCW'><dir id='OsLCW'><q id='OsLCW'></q></dir></style></legend>

        在 Rails 3.1 中,如何将 CoffeeScript(或 JavaScript)的执行限制为特定的控制器和动作?

        How do you limit CoffeeScript (or JavaScript) execution to a particular controller and action in Rails 3.1?(在 Rails 3.1 中,如何将 CoffeeScript(或 JavaScript)的执行限制为特定的控制器和动作?)
        <i id='DQXaI'><tr id='DQXaI'><dt id='DQXaI'><q id='DQXaI'><span id='DQXaI'><b id='DQXaI'><form id='DQXaI'><ins id='DQXaI'></ins><ul id='DQXaI'></ul><sub id='DQXaI'></sub></form><legend id='DQXaI'></legend><bdo id='DQXaI'><pre id='DQXaI'><center id='DQXaI'></center></pre></bdo></b><th id='DQXaI'></th></span></q></dt></tr></i><div id='DQXaI'><tfoot id='DQXaI'></tfoot><dl id='DQXaI'><fieldset id='DQXaI'></fieldset></dl></div>

          <tfoot id='DQXaI'></tfoot>

          <small id='DQXaI'></small><noframes id='DQXaI'>

              <tbody id='DQXaI'></tbody>

            • <legend id='DQXaI'><style id='DQXaI'><dir id='DQXaI'><q id='DQXaI'></q></dir></style></legend>
                • <bdo id='DQXaI'></bdo><ul id='DQXaI'></ul>
                  本文介绍了在 Rails 3.1 中,如何将 CoffeeScript(或 JavaScript)的执行限制为特定的控制器和动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  The new Rails 3.1 asset pipeline is really nice, but since all CoffeeScript (or JavaScript) files get melded down into a single file that is included in every page, it raises this question:

                  How do I limit the execution of my script to a particular controller or action? Is there a way within my CoffeeScript to know which controller and action was used during the request so that I can put conditional statements in my script?

                  Or am I approaching this the wrong way altogether?

                  解决方案

                  Trevor Burnham answers this question nicely here: How do I associate a CoffeeScript file with a view?

                  He says:

                  There are two common approaches:

                  1. Make behavior conditional on the presence of a particular element. For instance, code to run a signup sheet should be prefaced with something like

                    if $('#signup').length > 0

                  2. Make behavior conditional on a class on the body element. You can set the body class using ERB. This is often desirable for stylesheets as well. The code would be something like

                    if $('body').hasClass 'user'

                  And if you're interested in CoffeeScript, Trevor is working on a book that looks to be very good: http://pragprog.com/titles/tbcoffee/coffeescript

                  这篇关于在 Rails 3.1 中,如何将 CoffeeScript(或 JavaScript)的执行限制为特定的控制器和动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                  <i id='Pncsa'><tr id='Pncsa'><dt id='Pncsa'><q id='Pncsa'><span id='Pncsa'><b id='Pncsa'><form id='Pncsa'><ins id='Pncsa'></ins><ul id='Pncsa'></ul><sub id='Pncsa'></sub></form><legend id='Pncsa'></legend><bdo id='Pncsa'><pre id='Pncsa'><center id='Pncsa'></center></pre></bdo></b><th id='Pncsa'></th></span></q></dt></tr></i><div id='Pncsa'><tfoot id='Pncsa'></tfoot><dl id='Pncsa'><fieldset id='Pncsa'></fieldset></dl></div>
                • <small id='Pncsa'></small><noframes id='Pncsa'>

                    <tbody id='Pncsa'></tbody>
                      <bdo id='Pncsa'></bdo><ul id='Pncsa'></ul>

                        • <legend id='Pncsa'><style id='Pncsa'><dir id='Pncsa'><q id='Pncsa'></q></dir></style></legend>

                          <tfoot id='Pncsa'></tfoot>