小编rud*_*ph9的帖子

从Rakefile执行bash命令

我想bash从一个执行一些命令Rakefile.

我在我的尝试中尝试了以下内容 Rakefile

task :hello do
  %{echo "World!"}
end
Run Code Online (Sandbox Code Playgroud)

但在执行rake hello时没有输出?如何从Rakefile执行bash命令?

注意:这不是重复,因为它具体询问如何从Rakefile执行bash命令.

ruby bash rake

66
推荐指数
4
解决办法
4万
查看次数

haml默认情况下

有没有办法配置rails默认使用haml,即生成脚手架时生成的scaffold_name/index.html.haml是而不是scaffold_name/index.html.erb.

类似于您可以添加config.sass.preferred_syntax = :sass到默认情况config/application.rbscaffold_name.sass生成的方式.

尝试添加以下内容 config/application.rb

config.generators do |g| 
  g.template_engine :haml
end
Run Code Online (Sandbox Code Playgroud)

但结果如下

$ rails generate scaffold foo name:string
  invoke  active_record
  create    db/migrate/20120208152550_create_foos.rb
  create    app/models/foo.rb
  invoke    test_unit
  create      test/unit/foo_test.rb
  create      test/fixtures/foos.yml
   route  resources :foos
  invoke  scaffold_controller
  create    app/controllers/foos_controller.rb
   error    haml [not found]
  invoke    test_unit
  create      test/functional/foos_controller_test.rb
  invoke    helper
  create      app/helpers/foos_helper.rb
  invoke      test_unit
  create        test/unit/helpers/foos_helper_test.rb
  invoke  assets
  invoke    coffee
  create      app/assets/javascripts/foos.js.coffee
  invoke    sass
  create      app/assets/stylesheets/foos.css.sass
  invoke  sass
  identical    app/assets/stylesheets/scaffolds.css.sass
$ rails …
Run Code Online (Sandbox Code Playgroud)

haml ruby-on-rails ruby-on-rails-3.2

44
推荐指数
4
解决办法
2万
查看次数

在Controller中调用模型方法

我在这里有一定的困难,我无法成功地调用它属于一种方法ProjectPage 模型ProjectPage 控制器.

我在我的ProjectPage控制器中:

def index
  @searches = Project.published.financed     
  @project_pages = form_search(params)
end
Run Code Online (Sandbox Code Playgroud)

在我的ProjectPage 模型中:

def form_search(searches)
  searches = searches.where('amount > ?', params[:price_min]) if check_params(params[:price_min])
  @project_pages = ProjectPage.where(:project_id => searches.pluck(:'projects.id'))
end
Run Code Online (Sandbox Code Playgroud)

但是,我无法成功调用该form_search 方法.

methods controller model ruby-on-rails instantiation

37
推荐指数
2
解决办法
6万
查看次数

部署到heroku时清理bundler缓存

每当我使用heroku_san gem部署到Heroku(Ruby on Rails应用程序)时,它会说:

Cleaning up the bundler cache.
Would have removed sitemap_generator (2.0.1.pre1)
Would have removed newrelic_rpm (3.5.5.38)
Would have removed httparty (0.10.0)
Would have removed thor (0.16.0)
Would have removed ckeditor (3.7.1)
Would have removed fog (1.8.0)
Would have removed rake (0.9.2.2)
Would have removed dalli (2.6.0)
Run Code Online (Sandbox Code Playgroud)

(或者我之前部署中可能拥有的任何其他旧gem)如何清除Heroku应用程序中的bundler缓存?我试着跑:

heroku run bundle clean --force
Run Code Online (Sandbox Code Playgroud)

但它没有帮助.

谁能告诉我如何在Heroku中清理捆绑缓存?或者如果我应该忽略这个消息?

ruby-on-rails heroku bundler heroku-san

33
推荐指数
2
解决办法
9608
查看次数

使用正则表达式验证数值范围

我的输入数字是一个int.但输入数字必须在-2055到2055的范围内,我想通过使用正则表达式来检查.

那么无论如何要写一个正则表达式来检查一个数字是否在(-2055,2055)中?

if语句用于检查数字是否在范围内更容易.但是我正在写一个解释器,所以我应该使用正则表达式来检查输入数字

regex ocaml

29
推荐指数
6
解决办法
7万
查看次数

循环移位c

以下代码如何工作以及变量的含义:

y = (x << shift) | (x >> (sizeof(x)*CHAR_BIT - shift));
Run Code Online (Sandbox Code Playgroud)

我在循环转换文章中找到了但没有解释它是如何工作的.

c

26
推荐指数
3
解决办法
4万
查看次数

Node.js - 带有'request'模块的PUT

我正在使用Node.js中的请求模块来执行put请求.我的代码看起来像这样

var request = require('request');
var data = {foo: "bar", woo: "car"};

request({
   method: 'PUT',
   uri: myURL,
   multipart: [{
       'content-type':'application/json',
       body: JSON.stringify(data) 
   }]
}, function(error, request, body){
   console.log(body);
});
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到一个错误:

"不支持的内容类型:application/json"

javascript http-put node.js

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

调用用咖啡脚本定义的函数?

我有以下coffeescript代码来生成和警告框:

show_alert = () ->
  alert("Hello! I am an alert box!")
Run Code Online (Sandbox Code Playgroud)

编译为:

(function() {
  var show_alert;

  show_alert = function() {
    return alert("Hello! I am an alert box!");
  };

}).call(this);
Run Code Online (Sandbox Code Playgroud)

在我的HTML中我有以下内容

<input onclick='show_alert()' type='button' value='Show alert box' />
Run Code Online (Sandbox Code Playgroud)

但是,没有显示警告框?以下是从浏览器复制的html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Test Rails Application</title>
    <style type='text/css'>.application h1 {
  color: lime; }
</style>
    <script type='text/javascript'>(function() {
  var show_alert;

  show_alert = function() {
    return alert("Hello! I am an alert box!");
  };

}).call(this);
</script>
  </head>
  <body> …
Run Code Online (Sandbox Code Playgroud)

html javascript coffeescript

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

利用CoffeeScript`extens`与Backbone.js`extens`之间的基本区别

使用CoffeeScript extends与Backbone.js 之间的根本区别是extend什么?

例如,怎么样

class User extends Backbone.Model
Run Code Online (Sandbox Code Playgroud)

不同于

User = Backbone.Model.extend()
Run Code Online (Sandbox Code Playgroud)

inheritance coffeescript backbone.js

18
推荐指数
1
解决办法
1824
查看次数

Bundler无法找到gem的兼容版本,更新了Rails app

创建一个全新的rails应用程序之后在官方rails博客文章后,尝试将应用程序转换为rails 3.2.0.rc2会产生以下结果

Updated Gemfile to depend on rails ~> 3.2.0.rc2
    gem 'rails', '~>3.2.0.rc2'
Updated Gemfile to depend on sass-rails ~> 3.2.3
    gem 'sass-rails',   '~> 3.2.3'

$ bundle install
Fetching source index for http://rubygems.org/
Bundler could not find compatible versions for gem "activesupport":
  In snapshot (Gemfile.lock):
    activesupport (3.1.1)

  In Gemfile:
    rails (~> 3.2.0.rc2) ruby depends on
      activesupport (= 3.2.0.rc2) ruby

Running `bundle update` will rebuild your snapshot from scratch, using 
only the gems in your Gemfile, which may resolve …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-1.9.3 ruby-on-rails-3.2

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