小编Bla*_*ake的帖子

将css类添加到rails link_to helper

我正在尝试使用以下代码使用css设置rails链接的样式:

<%= link_to "Learn More", :controller => "menus", :action => "index", :class => "btn btn-inverse" %>
Run Code Online (Sandbox Code Playgroud)

我希望这会创建一个如下所示的链接:

<a href="menus/" class="btn btn-inverse">Learn More</a>
Run Code Online (Sandbox Code Playgroud)

相反,rails正在渲染这个 -

<a href="/menus?class=btn+btn-inverse">Learn More</a>
Run Code Online (Sandbox Code Playgroud)

有没有其他人有这个问题/知道我做错了什么?我知道我可以通过手动创建锚标记而不是使用帮助程序来避免这个问题,但我想知道是否有办法将css类信息传递给帮助程序本身.我正在使用Rails 3.2.6.

谢谢!

ruby-on-rails

55
推荐指数
2
解决办法
8万
查看次数

Bootstrap的远程模态对话框不起作用

我在Twitter Bootstrap api中使用远程模态对话框时遇到问题.

我正在尝试使用远程html页面中的内容加载模式对话框.我有两个页面,一个包含按钮(modal-remote.html),另一个包含我希望在单击按钮时显示的内容(modal-target.html).

modal-remote.html:

<!DOCTYPE html>
<html lang="en">
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
    <script src="bootstrap/js/jquery.js"></script>
    <script src="bootstrap/js/bootstrap.js"></script>

<a href="modal-target.html" data-target="#myModal" role="button" class="btn" data-toggle="modal">
    Launch demo modal</a>

</html>
Run Code Online (Sandbox Code Playgroud)

这是我的目标(或远程)页面的代码

modal-target.html:

<html>
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
    <script src="bootstrap/js/jquery.js"></script>
    <script src="bootstrap/js/bootstrap.js"></script>

    <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Modal header</h3>
      </div>
      <div class="modal-body">
        <p>The quick brown fox jumps over the lazy dog. </p>
      </div>
      <div class="modal-footer">
        <button class="btn" data-dismiss="modal" …
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap

10
推荐指数
1
解决办法
2万
查看次数

在Rails服务器上设置跨域调用

我正在开发一个Rails API和一个单独的html5应用程序.他们不共享相同的域.如何设置我的Rails应用程序以接受跨域请求?我已将以下内容添加到ApplicationController的顶部,但没有任何运气 -

  before_filter :set_access_control_headers

  def set_access_control_headers
    headers['Access-Control-Allow-Origin'] = 'http://myfrontend.com:3002'
    headers['Access-Control-Request-Method'] = 'GET, OPTIONS, HEAD'
    headers['Access-Control-Allow-Headers'] = 'x-requested-with,Content-Type, Authorization'
  end
Run Code Online (Sandbox Code Playgroud)

我在其他应用上的javascript看起来如下 -

var req = $.ajax({
  url: url,
  type: "GET",
  crossDomain: true,

  success: function(data, textStatus, jqXHR)
  {
     alert('success');
  },
  error: function(jqXHR, textStatus, errorThrown)
  {
     alert('error');
  }
});
Run Code Online (Sandbox Code Playgroud)

当我运行此请求时,我在服务器日志中获得以下内容 -

Started OPTIONS "/api/search?location_uuid=22222222222222222" for 127.0.0.1 at 2013-07-15 16:49:56 -0400
Processing by Api::V1::SearchController#index as JSON
  Parameters: {"location_uuid"=>"22222222222222222"}
WARNING: Can't verify CSRF token authenticity
  User Load (20.5ms)  SELECT "users".* FROM "users" ORDER BY …
Run Code Online (Sandbox Code Playgroud)

javascript jquery ruby-on-rails cross-domain

9
推荐指数
1
解决办法
7296
查看次数

使用亚马逊 step 函数,如何编写引用当前时间的选择运算符?

在 aws-step 函数文档中,似乎可以编写一个“选择”状态来比较当前状态的变量。但是,是否可以编写引用当前时间的时间戳比较?例如,假设我想,当我状态的时间才能启用特定状态$.myTime属性TimestampGreaterThan[current time]。例如:

{
   "Variable": "$.myTime",
   "TimestampGreaterThan": "<the current time>",
   "Next": "MyTimeSpecificState"
}
Run Code Online (Sandbox Code Playgroud)

是否可以参考当前时间,或者我是否必须在单独的任务中手动设置状态?

aws-step-functions

7
推荐指数
2
解决办法
3144
查看次数

"ajax:成功"被召唤两次

我正在使用jquery_ujs发送简单的帖子请求.我将回调函数绑定到"ajax:success"事件.但是,对于每个成功的帖子,都会调用此回调两次.

我知道这与其他问题类似,但我检查了我的源代码,它似乎没有加载jquery_ujs.js文件两次(正如许多响应所建议的那样).

    $(".new_item").bind("ajax:success", 
    function(xhr, data, status) 
    {
                 /* this is called twice for each call!*/
    }
Run Code Online (Sandbox Code Playgroud)

任何人有任何指针?谢谢!

jquery ruby-on-rails

3
推荐指数
1
解决办法
8073
查看次数

使用tyeporm迁移,如何指定特定的连接?

我正在使用typeorm并尝试在测试连接上运行迁移。在我的ormconfig.json文件中,我指定了两个单独的连接,如下所示:

[{
  "name": "default",
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "username",
  "password": "",
  "database": "database",
  "entities": [
    "build/entity/**/*.js"
  ],
  "migrations": [
    "build/migration/**/*.js"
  ],
  "synchronize": false,
  "autoSchemaSync": true,
  "logging": false,
  "cli": {
    "migrationsDir": "src/migration",
    "entitiesDir": "src/entity",
    "subscribersDir": "src/subscriber"
  }
},
{
  "name": "test",
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "username",
  "password": "",
  "database": "database-test",
  "entities": [
    "build/entity/**/*.js"
  ],
  "migrations": [
    "build/migration/**/*.js"
  ],
  "synchronize": false,
  "autoSchemaSync": true,
  "logging": false,
  "cli": {
    "migrationsDir": "src/migration",
    "entitiesDir": "src/entity",
    "subscribersDir": "src/subscriber"
  }
}]
Run Code Online (Sandbox Code Playgroud)

如何 …

database-migration typeorm

3
推荐指数
1
解决办法
2624
查看次数