所以,我才刚刚意识到我完全不知道什么链轮在轨道上.
当使用bootstrap或实现时,请求在文件中包含sprocket(bootstrap-sprocket或materialize-sprocket)application.js.
我搜索的所有内容都谈到了资产管道,让我更加困惑.
根据红宝石指南,
资产管道在技术上不再是Rails 4的核心功能,它已经从框架中提取到sprockets-rails gem中.
当我这样做时bundle show sprockets-rails,我得到了:
/Users/Sunday/workspace/resilience/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.1
Run Code Online (Sandbox Code Playgroud)
这表明我至少有宝石.
但是我的困惑和我的问题是,重要的是什么sprockets,而不是sprockets-rails像其他宝石一样bootstrap,materialize而且可能还有其他宝石sprockets,尤其是在他们的javascript文件中?
谢谢.
我试图用色器件和devise_token_auth在我的应用程序进行身份验证.
我正在覆盖注册控制器,如下所示:
module Overrides
class RegistrationsController < DeviseTokenAuth::RegistrationsController
## I am doing these to go around the `Can't verify CSRF token authenticity` Error.
# skip_before_action :valid_authenticity_token, only: :create
protect_from_forgery :except => :create
def sign_up_params
params.require(:user).permit(:email, :password, :password_confirmation, :name, :nickname)
end
end
end
Run Code Online (Sandbox Code Playgroud)
我也使用swagger docs api发送我的参数如下:
swagger_api :create do
summary "Sign up a new user"
param :form, "user[email]", :string, :required, "Email of the new user"
param :form, "user[password]", :string, :required, "Password of the new user" …Run Code Online (Sandbox Code Playgroud) 我的网站是Wordpress-site创建的PHP.
我已将永久链接默认更改为postname.它工作得很好Chrome,Firefox但在IE8中没有.首页显示正确但当我单击指向另一个页面的链接时,它会显示404找不到页面错误.
我正在使用Wordpress版本3+.
.htaccess文件是
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud)
其中WordPress是文件夹名称.也是在apache中,rewrite_module是启用的
好的,所以我知道在处理非常大的数据时,我们可以使用find_in_batches哪个,据我所知,它Model.all.each以非常快的方式完成工作,效率更高
现在,我有一个非常大的数据,我正在尝试删除,我正在考虑使用它find_in_batches来批量删除它们.
以下是我所拥有的(来自rake任务database.rake):
old_messages = TextMessage.where("created_at < ?", number.days.ago )
old_messages.find_in_batches do |batch|
batch.delete_all
end
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我收到以下错误:
ArgumentError: wrong number of arguments (0 for 1..3)
/Users/Sunday/.rvm/gems/ruby-2.2.0/gems/httparty-0.13.5/lib/httparty.rb:66:in `logger'
/Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/delegation.rb:94:in `public_send'
/Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/delegation.rb:94:in `block in method_missing'
/Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation.rb:302:in `scoping'
/Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/delegation.rb:94:in `method_missing'
/Users/Sunday/.rvm/gems/ruby-2.2.0/gems/activerecord-4.2.2/lib/active_record/relation/batches.rb:112:in `find_in_batches'
/Users/Sunday/workspace/resilience/lib/tasks/database.rake:18:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
database.rake第18行的地方是:old_messages.find_in_batches do |batch|.
那么,是否有可能find_in_batches像我想要的那样用于删除?如果答案是肯定的,那么我做错了什么.感谢所有回复.
我正在设置一个 ubuntu 实例来托管 Rails 应用程序...当我安装 postgresql 作为数据库时,我打开了两个不同的资源来检查它,除了不同之处:
一:
sudo apt-get install postgresql postgresql-contrib
Run Code Online (Sandbox Code Playgroud)
和另一个:
sudo apt-get install postgresql-common
Run Code Online (Sandbox Code Playgroud)
postgresql-contrib所以,这就引出了我非常基本的问题:和 之间有什么区别postgresql-common?
感谢大家的回复。
我有一个id数组,我想使用活动记录查询从数据库中找到它们各自的记录.例如:ids = [2, 3, 1]
现在,让我找到一个特定模型的所有记录,其ID是数组中的一个,在较低版本的rails中,我想我可以做类似的事情:
Model.find_all_by_id([2, 3, 1])
Run Code Online (Sandbox Code Playgroud)
但根据这篇文章,
These methods were deprecated on 4.0 and removed at 4.1. If you want to
keep sing then you need to include this gem
https://github.com/rails/activerecord-deprecated_finders
Run Code Online (Sandbox Code Playgroud)
我的问题是,我不能在rails4.2中做到这一点,而不必包含一个宝石?
谢谢.
我已经database-cleaner为我的 rails 4 应用程序进行了配置,每次运行测试时,我发现我的数据库在test和development环境中都被清除了。
我的配置rails_helper如下:
ENV["RAILS_ENV"] ||= 'test'
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'database_cleaner'
Rails.env = "test"
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec …Run Code Online (Sandbox Code Playgroud) 根据Stephen Hagemann的这篇文章,我正试图为我的一个rake任务写一个Rspec测试.
lib/tasks/retry.rake:
namespace :retry do
task :message, [:message_id] => [:environment] do |t, args|
TextMessage.new.resend!(args[:message_id])
end
end
Run Code Online (Sandbox Code Playgroud)
spec/tasks/retry_spec.rb:
require 'rails_helper'
require 'rake'
describe 'retry namespace rake task' do
describe 'retry:message' do
before do
load File.expand_path("../../../lib/tasks/retry.rake", __FILE__)
Rake::Task.define_task(:environment)
end
it 'should call the resend action on the message with the specified message_id' do
message_id = "5"
expect_any_instance_of(TextMessage).to receive(:resend!).with message_id
Rake::Task["retry:message[#{message_id}]"].invoke
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此测试时,我收到以下错误:
Don't know how to build task 'retry:message[5]'
Run Code Online (Sandbox Code Playgroud)
另一方面,当我运行没有参数的任务时:
Rake::Task["retry:message"].invoke
Run Code Online (Sandbox Code Playgroud)
我能够调用rake任务,但测试失败,因为没有message_id.
我将参数传递给rake任务的方式有什么问题? …
我有一个HTTParty请求,其响应格式如下:
#<HTTParty::Response:0x7fe078a60f58
parsed_response={"groups"=>
[{"id"=>"11111", "name"=>"foo", "reference"=>nil},
{"id"=>"22222", "name"=>"bar", "reference"=>nil}]
},
@response=#<Net::HTTPOK 200 OK readbody=true>,
@headers={
"date"=>["Wed, 25 Nov 2015 13:05:27 GMT"],
"content-type"=>["application/xml; charset=utf-8"],
"content-length"=>["1752"], "connection"=>["close"],
"status"=>["200 OK"],
"etag"=>["\"47f4a2f4b888491d07dc21b009e6f8a4\""],
"x-frame-options"=>["DENY"],
"cache-control"=>["private, max-age=0, must-revalidate"],
"p3p"=>["CP=\"CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE\""]}
>
Run Code Online (Sandbox Code Playgroud)
我需要在Rspec测试中使用 web-mock 来存根此请求。这就是我所做的:
stub_request(
:get, url
)
.with(:headers => {'Content-Type'=>'application/xml'})
.to_return(
:status => 200,
:body => {
"groups"=>[
{"id"=>"11111", "name"=>"foo", "reference"=>nil},
{"id"=>"22222", "name"=>"bar", "reference"=>nil}
]
},
:headers …Run Code Online (Sandbox Code Playgroud) 我有一个 model( Verification),我正在尝试验证其唯一性。
但是,我需要将唯一性范围限定为状态(枚举),如下所示:
class Verification < ActiveRecord::Base
belongs_to :profile
scope :active, -> { where('status NOT IN (?)',
['approved', 'rejected'].map{ |s| self.statuses[s]
}
) }
validates :profile, uniqueness: { scope: :active,
message: "can have only one active per time." }
enum status: [:requested, :processing, :approved, :rejected]
end
Run Code Online (Sandbox Code Playgroud)
我不希望一个个人资料一次有多个主动验证。
active但是当我像上面那样做时,它会引发错误,因为我的表中没有命名的列verifications。
如何验证仅适用于主动验证的配置文件的唯一性?谢谢。
ruby ×4
activerecord ×3
rspec ×3
devise ×1
httparty ×1
javascript ×1
php ×1
postgresql ×1
rake ×1
rake-task ×1
sprockets ×1
validation ×1
webmock ×1
wordpress ×1