我有一堆.coffee文件,我需要加入一个文件.
我有像rails应用程序设置的文件夹:
/src/controller/log_controller.coffee
/src/model/log.coffee
/src/views/logs/new.coffee
Run Code Online (Sandbox Code Playgroud)
Coffeescript有一个命令,允许您将多个coffeescripts连接到一个文件中,但它似乎只能用于一个目录.例如,这工作正常:
coffee --output app/controllers.js --join --compile src/controllers/*.coffee
Run Code Online (Sandbox Code Playgroud)
但我需要能够包含一堆类似于这个非工作命令的子目录:
coffee --output app/all.js --join --compile src/*/*.coffee
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?是否有UNIX方法传递子目录中的所有文件的列表?
我在OSX中使用终端.
它们都必须加在一个文件中,因为否则每个单独的文件都会被编译和包装:
(function() { }).call(this);
Run Code Online (Sandbox Code Playgroud)
这打破了一些函数调用的范围.
我正在使用运行一个简单的查找全部并使用willpaginate进行分页,但我也希望将查询按用户排序.想到的第一个解决方案就是使用params [:sort]
http://localhost:3000/posts/?sort=created_at+DESC
@posts = Post.paginate :page => params[:page], :order => params[:sort]
Run Code Online (Sandbox Code Playgroud)
但他的方法的问题是查询默认为按ID排序,我希望它是created_at.
这是一种安全的排序方法,有没有办法默认为created_at?
在backbone.js我正在更新一个类别模型:
@category.save {
name : category_name,
}
Run Code Online (Sandbox Code Playgroud)
这样可以很好地保存并在骨干网中正确更新集合.但是在rails服务器上由于路由错误而无法保存:
Started PUT "/categories" for 127.0.0.1 at 2011-05-24 11:18:16 -0400
ActionController::RoutingError (No route matches "/categories"):
Run Code Online (Sandbox Code Playgroud)
问题是rails希望PUT/update有一个包含id"/ categories /:id"的url,而不仅仅是"/ categories"
我通过更改模型网址测试了这个:
class Category extends Backbone.Model
name: 'category'
url: ->
host + '/categories'
Run Code Online (Sandbox Code Playgroud)
至
class Category extends Backbone.Model
name: 'category'
url: ->
host + '/categories/2'
Run Code Online (Sandbox Code Playgroud)
这很好用.
Started PUT "/categories/2" for 127.0.0.1 at 2011-05-24 11:44:08 -0400
Processing by CategoriesController#update as JSON
Parameters: {"category"=>{"created_at"=>2010-03-14 16:30:07 -0400, "id"=>2, "name"=>"Lunchr5", "updated_at"=>2010-03-14 16:30:07 -0400, "user_id"=>1}, "api_key"=>"s1boakDIav30V6DzOFsY", "id"=>"2"}
User Load (0.2ms) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的网站上强制使用SSL.我希望有一个响铃式中间件,如果它只是http,则使用https将站点重定向到相同的URL
我编写了以下代码,但除了检查请求方案并打印应该重定向到的URL之外,它并没有真正做任何事情.
(defn https-url [request-url]
(str (str (str (str "https://" (:server-name request-url) ":") (:server-port request-url))) (:uri request-url)))
(defn require-https
[handler]
(fn [request]
(let [page-request (handler request)]
(if (= (:scheme page-request) :http)
(println (https-url page-request))))))
(server/add-middleware require-https)
Run Code Online (Sandbox Code Playgroud)
我如何将其实现为真正的应用程序?
我正在使用黑色的clojure 1.2.
旁注:如何使用多个嵌套的str将多个字符串组合成一个字符串?
我试图在我的应用程序中检测Blackberry用户代理,这在我的开发版本中工作正常.但是,当我在生产中重新部署应用程序时,没有任何反应.
application_helper.rb
def blackberry_user_agent?
request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Blackberry)/]
end
Run Code Online (Sandbox Code Playgroud)
application.html.erb
<% if blackberry_user_agent? -%>
<div class="message">
<p>Using a Blackberry? <a href="http://mobile.site.ca/">Use the mobile optimized version</a>.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用rake tmp:cache清除缓存:清除并重启mongrel几次.显然,HTTP_USER_AGENT在生产中回归为零.我正在使用Nginx和一个mongrel集群.
我正在使用这段代码来模仿文件的上传方式:
def mock_file
file = File.new((Rails.root + "public/checklist_items_template.csv"),"r")
image = ActionDispatch::Http::UploadedFile.new(
:filename => "checklist_items_template.csv",
:type => "text/csv",
:head => "Content-Disposition: form-data;
name=\"checklist_items_template.csv\";
filename=\"checklist_items_template.csv\"
Content-Type: text/csv\r\n",
:tempfile => file)
return image
end
Run Code Online (Sandbox Code Playgroud)
在rspec测试中,它是POST给控制器:
post :create, :legal_register_id => "1", :register => {"file" => mock_file}
Run Code Online (Sandbox Code Playgroud)
但它在实际控制器中打破了这一行:
CSV.parse(params[:register][:file].read.force_encoding('UTF-8'))
Run Code Online (Sandbox Code Playgroud)
因为params [:register] [:file]被解释为字符串而不是actiondispatch对象:
undefined method `read' for "#<ActionDispatch::Http::UploadedFile:0x00000108de3da8>":String
Run Code Online (Sandbox Code Playgroud)
这是rspec的标准行为吗?有没有办法通过参数传递对象?
我有一个任务列表(name,starts_at),我试图在日常视图中显示它们(就像iCal一样).
def todays_tasks(day)
Task.find(:all, :conditions => ["starts_at between ? and ?", day.beginning, day.ending]
end
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何将Time.now如"2009-04-12 10:00:00"动态转换为当天的开始(和结束),以便我可以进行比较.
我想抓住当前网址的最后一部分:
网址:http://example.com/test/action
我想抓住"行动".
该结构中的URL始终一致.但最后它可能会有一些额外的参数.
这是使用原型框架的rails应用程序.在rails中它将是params [:id].
我有一个ajax请求,返回如下的值列表:
"1,2,3,4,5,6"
Run Code Online (Sandbox Code Playgroud)
我需要它是一个带数字的javascript数组:
[1,2,3,4,5,6]
Run Code Online (Sandbox Code Playgroud)
我试过了:
var array = new Array("1,2,3,4,5,6".split(","))
Run Code Online (Sandbox Code Playgroud)
但数字仍然是输出中的字符串:
["1","2","3","4","5","6"]
Run Code Online (Sandbox Code Playgroud)
是否有一种干净的方式将其作为编号数组?最好不编写函数来迭代它?
我刚刚将我的应用程序升级到rails 3.1,现在每当我运行测试时,我的终端都会获得大量的SQL输出.
例如:
(1.0ms) TRUNCATE TABLE `users`;
(0.1ms) SET FOREIGN_KEY_CHECKS = 1
. Company Load (0.3ms) SELECT `companies`.* FROM `companies` LIMIT 1
Sector Load (0.3ms) SELECT `sectors`.* FROM `sectors` WHERE `sectors`.`name` = 'General' LIMIT 1
(0.1ms) BEGIN
(0.3ms) SELECT 1 FROM `sectors` WHERE `sectors`.`name` = BINARY 'General 63' LIMIT 1
SQL (0.2ms) INSERT INTO `sectors` (`created_at`, `name`, `price_in_cents`, `updated_at`) VALUES ('2011-09-13 20:46:48', 'General 63', 0, '2011-09-13 20:46:48')
(0.3ms) COMMIT
Run Code Online (Sandbox Code Playgroud)
有没有办法禁用它?
我正在使用rspec instafail,我再也看不到它了,因为它充斥着SQL输出.
我尝试添加本文中的内容,但它没有帮助:http://tesoriere.com/2011/05/28/rails-3.1---sql-logging-to-stdout-during-testing--with-rspec- -test单元-或黄瓜- /
ruby ×3
javascript ×2
rspec ×2
backbone.js ×1
clojure ×1
coffeescript ×1
jquery ×1
noir ×1
rspec-rails ×1
terminal ×1