English 中文(简体)
利用铁路 3.2 是否应当避免将有条件的 Java纳入意见之中?
原标题:Using Rails 3.2, Should inclusion of conditional JavaScript in the views be avoided?

众所周知,铁路框架建议严格地将贾瓦文和Html通过所谓的“联合司法”分离,但有时我认为有必要在我的《意见》中列入 Java文的 imp。 我首先要知道这是否正确? 或者它是否拥有?

我发现自己这样做的最常见情况是,例如,我有这样的条件:

= form_for @place do |f|
  %h5 Address:
  .input-prepend
    %span{ :class => "add-on" } 
      %i{ :class => "icon-road" }
    = f.text_field :address

  %h5 Name:
  .input-prepend
    %span{ :class => "add-on" } 
      %i{ :class => "icon-pencil" }
    = f.text_field :name

  = f.hidden_field :latitude
  = f.hidden_field :longitude

  #post-button
    %button{ :class => "btn btn-primary", :type => "submit" } Post it! 

- unless logged_in?
  :javascript
    $( #post-button > button, .input-prepend input ).addClass( disabled );
    $( .input-prepend input ).addClass( disabled );
    $( .input-prepend input ).attr( disabled ,  disabled );
    new PopOver().setPopOver($( #post-button > button ), "You must be logged in to register your Business");

如果情况并非如此,我想知道:it s OK,以备有,还是? (通过) 在什么情况下,我不知道如何这样做......

请允许我了解你的想法,我需要了解铁路开发商如何处理这些类型的局势,这样,如果我爱读你的答案的话。

提前感谢!

PS。 奥赫,请让我看到关于你如何尽可能解决这一问题的守则选择。

最佳回答

美国航天学会当然是目前铁路界最受欢迎的办法,但不同的开发商将它带到不同的极端。 我完全知道这一点,因为根据他们的说法,你不知道,在你刚刚看着html(我个人认为是罚款的)时,某个因素是否会通过联合材料采取行动(因为超文本只是关于结构,而不是功能)。

就你的特殊问题而言,很明显,你不能仅仅把 j子装入一个固定的 j印夹,装上页,因为 j口不会知道你是否被gged。 你们可以在人力部某个地方提出一个指标,表明你有gged,但我却不容易 s。 根据服务器数据决定是否使用javascript的一个相当安全的方法是向服务器发出AJAX电话,具体如下:

  1. Javascript loaded by the browser makes a get AJAX call to the server (using $.getScript() with jQuery)
  2. The action in your Rails controller responds to the AJAX call with a .js.erb template
  3. You can put as much server side logic as you would like into your .js.erb template (i.e. only run the javascript if the user is not logged in)

这样,你就把 j(功能)放在了你的html(结构)之外,同时仍然能够作出服务器方面的决定。 http://railscasts.com/episodes/169-dynamic-page-caching-revised”rel=“nofollow”

例如,如果适用的话。 j 您:

$.getScript( /users/show )

然后,这将称作<代码>UsersController#show行动。 然后,铁路将寻找<代码>应用程序/views/users/show.js.erb模板。 在这份档案中,你可以有:

<% unless logged_in? %>
  $( #post-button > button, .input-prepend input ).addClass( disabled );
  $( .input-prepend input ).addClass( disabled );
  $( .input-prepend input ).attr( disabled ,  disabled );
  new PopOver().setPopOver($( #post-button > button ), "You must be logged in to register your Business");
<% end %>

浏览器收到服务器的答复后,单单单自动操作。 在这种情况下,只有在用户被打上gged锁时,才会使用 j。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.