Tag: ruby

Rails 4 / postgresql index – 我应该使用一个datetime列作为索引filter,它可以有无限数量的值吗?

我需要优化查询以获取某个国家/地区的所有交易,然后才能在某个特定日期时间之前访问用户。 我的计划是实现以下索引 add_index(:deals,[:country_id,:last_user_access_datetime]) 我怀疑这个索引的相关性和有效性,因为列last_user_access_datetime可以具有日期的任何值ex:13/09/2015 3:06 pm并且它将经常更改(每次用户访问它时更新)。 如果我使用这个索引,这会使无限数量的值被索引? 我应该这样做还是避免使用’无限值的可能列,例如索引中的完全免费的datetime列?

在javascript文件上找到501 Method Not Found错误 – 更改名称然后工作 – 为什么?

我正在开发一个Ruby on Rails应用程序,并且有一个名为jquery.cookie.js的文件,没有客户端机器下载,因为服务器发回“501 Method Not Implemented”错误。 这在我的开发机器上不会发生。 不幸的是,我对这个特定的系统非常陌生,并且作为唯一的开发人员(没有与之前的开发人员联系),我很难过甚至可能是什么原因。 我的问题是 – 什么可能导致这个特定的JavaScript文件无法下载? 其他人那样做。 当我重命名文件(类似于jquery.cookee.js)时,它会毫无问题地下载。 显然,我不能将其作为一个永久的解决方案,因为代码中有太多的地方使用它,我害怕通过更改其名称来删除其他内容。 当然,非常感谢您的想法。

如何使可点击的hover背后的东西?

用户将鼠标hover在glyphicon-globe图像上,在其后面有一个类似按钮和注释表单。 当用户点击按钮或评论表单时没有任何反应。 我怎样才能点击全球背后的可点击内容? 视图 @challenge.id), class: “btn”, method: :post do %> Like CSS .image-container { position: relative; height: auto; #image-foreground { position: absolute; z-index: 2; opacity: 1; &:hover { opacity: 0; } } } .text-wrapper { opacity: 1; } 没有hover 徘徊

如何建立分页url​​的路径?

当用户#1喜欢/评论用户#2时,用户#2会收到通知: 通知/ _notifications.html.erb commented on 但是在用户#2点击通知后,由于我删除了activity_path ,因此它没有任何结果,如果我之前将其放回(notification.activity_id)我们会收到错误: 没有路由匹配{:action =>“show”,:controller =>“activities”,>:id => nil}缺少必需的键:[:id] 我不知道这是否可行,但点击通知用户#2将被带到活动的分页页面 。 通过gem will_paginate每页有20个活动,因此如果被注释的活动在第2页上,那么在点击活动时,用户#2应该被定向到:http: //0.0.0.0 : gem will_paginate /activities?page = 2 这至少会缩小注释对用户的活动供稿的位置。 活动/ index.html.erb activity.id), class: “btn”, method: :post do %> Like activities_controller.rb class ActivitiesController params[:page], :per_page => 20) end def show redirect_to(:back) end end 如果您发现可以这样做,请告诉我您是否需要更多代码:) UPDATE class NotificationsController < ApplicationController def index […]

在Heroku上安装rmagick gem的问题

我正在尝试将Rails应用程序推送到Heroku,但是当它尝试构建rmagick gem(在Gemfile中指定)时它失败了。 我在本地完成了bundle install ,应用运行正常。 但是,在预接收钩子中的Heroku上,在构建rmagick示例之后,我得到: make install /usr/ruby1.8.7/bin/ruby setup.rb install rm -f InstalledFiles —> lib mkdir -p /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib install RMagick.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/ —> lib/rvg mkdir -p /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install embellishable.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install pathdata.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install stylable.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install describable.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install deep_equal.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install misc.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install text.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install rvg.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install container.rb /disk1/tmp/build_3eu8mw7r34j0f/.bundle/gems/ruby/1.8/gems/rmagick-1.15.17/lib/rvg install […]

我想在我的spree扩展中添加新的javascript文件

我是铁杆新手。 我正在尝试构建Spree扩展以使用Braintree的插入式UI。 我正在尝试将新的braintree.js添加到我的扩展程序中。 这些是我到目前为止所做的步骤。 将/app/assets/javascripts/spree/frontend/添加到/app/assets/javascripts/spree/frontend/ 添加了//= require spree/frontend/braintree到app/assets/javascripts/spree/frontend/.js 。 在/config/initializers/创建了braintree.rb 。 该文件的内容: Braintree::Configuration.environment = :sandbox Braintree::Configuration.merchant_id = “merchant_id” Braintree::Configuration.public_key = “public_key” Braintree::Configuration.private_key = “private_key” 从我的狂欢商店我运行bundle install ,这是成功的。 Ran rails g :install ,它给出了以下错误: append vendor/assets/javascripts/spree/frontend/all.js append vendor/assets/javascripts/spree/backend/all.js insert vendor/assets/stylesheets/spree/frontend/all.css insert vendor/assets/stylesheets/spree/backend/all.css run bundle exec rake railties:install:migrations FROM=spree_hello_ext from “.” Would you like to run the migrations […]

Rails后台工作者总是第一次失败,第二次工作

我有一个sidekiq工作者在保存对象后触发: class Post < ActiveRecord::Base attr_accessible :description, :name, :key after_save :process def process ProcessWorker.perform_async(id, key) if key.present? end def secure_url key.match(/(.*\/)+(.*$)/)[1] end def nonsecure_url key.gsub('https', 'http') end end 工人看起来如下(它尚未完成……只是测试): class ProcessWorker include Sidekiq::Worker def perform(id, key) post = Post.find(id) puts post.nonsecure_url end end 奇怪的是,每次工作人员触发时,它最初会因以下错误而失败: undefined method `gsub’ for nil:NilClass 但是,当工人稍后重试时 – 它总是成功。 它真的感觉好像什么东西没有初始化它应该……但我似乎无法追踪它。

Rails – rake db:重置不清除我的数据库

这里是rails的新手,并尝试使用db \ seeds.rb文件等 首先,我想使用rake db:reset数据库中的所有数据,但它无法正常工作! 这是我的输出 C:\ Sites \ sportproject> rake db:reset 无法删除db / development.sqlite3:# db / development.sqlite3已经存在 – create_table(“sports”,{:force => true}) – > 0.0640s – create_table(“teams”,{:force => true}) – > 0.0340s – add_index(“teams”,[“sport_id”],{:name =>“index_teams_on_sport_id”}) – > 0.0160s – initialize_schema_migrations_table() – > 0.0000s – assume_migrated_upto_version(20130531012951,[“C:/ Sites / sportproject / db / migra] TE“]) – > […]

为什么我的Ruby版本会发生冲突?

当我在~home文件夹中运行ruby -v时,我得到: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0] 但现在我正在尝试运行一个应用程序,并且有一些缺失的gem。 搜索它们,我被告知使用Ruby 1.9运行这个应用程序,但在/ app文件夹中,当我运行ruby -v ,我得到: ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] 为什么会这样,我怎样才能恢复我的2.0。 当前版本的Ruby?

在has_many上通过:关联优雅地设置连接表属性

在我的Rails 3.2应用程序中, Users可以创建Articles Collections 。 Collections和Articles由has_many through: collections_articles关系连接。 我希望在将Article添加到Collection时将user_id存储在collections_articles连接表中。 (因此该应用程序可以稍后显示谁将文章添加到集合中)。 有一种优雅的方式来做到这一点? class CollectionsArticle collection_id article_id user_id belongs_to :collection belongs_to :article belongs_to :user 当用户将文章添加到集合中时,我只想使用铲子,因此: my_collection.articles << my_article 无论如何(优雅地)同时将连接表的user_id设置为current_user ? 或者是在连接表本身中显式创建记录的最佳方法: CollectionsArticle.create(article: @article, collection: @collection, user: current_user) 谢谢!