我想写几个小时的简单函数:
自创建以来已经过了多少时间?
我的尝试:
-time = DateTime.now.hour - (self.created_at.hour)
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何在Ruby on Rails中执行此操作?
我总是被迫使我的终端窗口两个双显示器宽,只是为了看到它们正确.我不是黄油GUI的坚持者,但这是迟钝的.
这个命令有漂亮的印记吗?
我刚刚升级到1.0.3,我的config/routes文件夹中的routes.rb文件似乎忽略了我所有的自定义路由.
我的routes.rb
JollyStore::Application.routes.draw do
# Mount Spree's routes
mount Spree::Core::Engine, :at => '/'
root :to => 'pages#index'
namespace :admin do
resources :wysiwygs
end
match 'about_us/', :to => "pages#about_us"
match 'services/', :to => "pages#services"
match 'raw_resources/', :to => "pages#raw_resources"
match 'contact_us/', :to => "pages#contact_us"
match 'privacy_policy/', :to => "pages#privacy_policy"
match 'return_policy/', :to => "pages#return_policy"
match 'refund_policy/', :to => "pages#refund_policy"
match 'cancellation_policy/', :to => "pages#cancellation_policy"
match 'delivery_shipping_policy/', :to => "pages#delivery_shipping_policy"
end
Run Code Online (Sandbox Code Playgroud)
如果我运行bundle exec rake routes,它将返回所有适当的路由.但当我尝试访问该特定页面时,我得到:
undefined local variable …Run Code Online (Sandbox Code Playgroud) 我想从S3容器中读取照片的几何图形.
当它在我的本地时,这工作:
def photo_geometry(style = :original)
@geometry ||= {}
@geometry[style] ||= Paperclip::Geometry.from_file photo.path(style)
end
Run Code Online (Sandbox Code Playgroud)
但是当我将模型切换到S3时它似乎不起作用..任何建议?
更重要的是,我正在尝试编写一些代码,允许我从S3中检索照片,允许用户裁剪它们,然后将它们重新上传回仍由回形针分配的S3.
编辑:
这是返回的错误:
Paperclip::NotIdentifiedByImageMagickError: photos/199/orig/greatReads.png is not recognized by the 'identify' command.
from /Users/daniellevine/Sites/hq_channel/vendor/gems/thoughtbot-paperclip-2.3.1/lib/paperclip/geometry.rb:24:in `from_file'
from /Users/daniellevine/Sites/hq_channel/app/models/photo.rb:68:in `photo_geometry'
from (irb):1
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚为什么页面在点击时不会导航到它的模板.URL更新,我没有JS错误..我相信它加载文件,但然后它无限加载控制器.我console.log('test!')在SessionsController的实例化中添加了一个后发现了这个.
布局
<div ng-view></div>
Run Code Online (Sandbox Code Playgroud)
我的看法
<a href="/testing"> My link of seriousness </a>
Run Code Online (Sandbox Code Playgroud)
我的JS
window.MainController = function($scope, $route, $routeParams, $location) {
$scope.$route = $route;
$scope.$location = $location;
$scope.$routeParams = $routeParams;
console.log($route);
console.log($location);
console.log($routeParams);
};
MainController.$inject = ["$scope", "$route"];
window.app = angular.module('web_client', [], function($routeProvider, $locationProvider) {
return $routeProvider.when('/testing', {
templateUrl: '/partials/other_stuff/index.html',
controller: 'MyController'
});
});
window.MyController = function($scope, $http) {
console.log('Infinite Loop!');
};
Run Code Online (Sandbox Code Playgroud)
在partials/sessions/new.html,我有大而光明:
FOOBAR!
Run Code Online (Sandbox Code Playgroud) 我很好奇是否有人可以在不使用S3的情况下使用Heroku进行回形针处理.我假设Heroku是一个只读系统,但必须有一些方法来保存图像.
我已经尝试了一些建议,但似乎没有任何东西可以删除它.当我升级到Mountain Lion OS X时,这种情况就开始发生了.任何时候我都会这样做git pull,它会显示出令人讨厌的空标题为MERGE_MSG的空编辑器.
如何防止在我的所有应用程序中全局弹出?
刚尝试在我的模型中编写一个简单的validates_presence_of,当错误尝试渲染时,它会调用:
Template is missing
Missing template posts/create with {:locale=>[:en, :en], :handlers=>[:builder, :rjs, :erb, :rhtml, :rxml, :haml], :formats=>[:html]} in view paths "/Users/johnsmith/Sites/shwagr/app/views"
Run Code Online (Sandbox Code Playgroud)
错误在Rails3中没有单独的视图吗?我以为那是Rails魔法..
好奇,如果有人有这个问题,或知道如何正确验证.
我的型号:
validates_presence_of :category, :name, :url
Run Code Online (Sandbox Code Playgroud)
我的控制器:
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
def create
@post = Post.new(params[:post])
if @post.valid? && current_user.posts << @post
respond_to do |format|
if @post.save
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
format.xml { render :xml => …Run Code Online (Sandbox Code Playgroud) 我想在这个字符串的末尾添加一个'/'.做这个的最好方式是什么?
>> params[:id]
"shirts"
Run Code Online (Sandbox Code Playgroud)
我想做params[:id] == "shirts/".如何/在该字符串的末尾添加a ?
我的字符串:
>> pp params[:value]
"07016,07023,07027,07033,07036,07060,07062,07063,07065,07066,07076,07081,07083,07088,07090,07092,07201,07202,07203,07204,07205,07206,07208,07901,07922,07974,08812,07061,07091,07207,07902"
Run Code Online (Sandbox Code Playgroud)
如何成为一组单独的数字,如:
["07016", "07023", "07033" ... ]
Run Code Online (Sandbox Code Playgroud)