因此,在Rails 4中not添加了使用查询的长期所需功能.
Article.where.not(title: 'Rails 3')
Run Code Online (Sandbox Code Playgroud)
是否为or查询添加了类似的支持,或者他们是否计划进行查询.浏览发行说明我找不到任何东西.
显然我试过了
Article.where(title: 'Rails 3').or(title: 'Rails 4')
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
我有一个独立的乘客运行的rails应用程序,它运行良好.我正在运行apache,并使用带反向代理的VirtualHost来为我的rails应用程序提供服务.这有效.但是,我的资产不是通过vhost提供的,而是提供代理错误.
我的httpd.conf
<VirtualHost *:80>
ServerName greekpeep_rails.nightowls.co
DocumentRoot /home/railsapps/www/greekpeep/public
ProxyPass / http://127.0.0.1:4000
ProxyPassReverse / http://127.0.0.1:4000
<Directory /home/railsapps/www/greekpeep/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
代理错误
代理错误
代理服务器从上游服务器收到无效响应.代理服务器无法处理请求GET/assets/application-6fc7d25aa72d2a014ae6b36136c2fbfc.css.
原因:DNS查找失败:127.0.0.1:4000assets
请注意,127.0.0.1:4000可以正常运行并正确地为资产提供服务.greekpeep_rails.nightowls.co加载页面,但不加载资产.
是否可以在返回子类的单个表继承上设置范围?
例如:
class Post < ActiveRecord::Base
scope :sticky, -> { where(type: 'StickyPost') }
end
class StickyPost < Post
end
Run Code Online (Sandbox Code Playgroud)
现在,当我调用sticky一组帖子时,我得到了一组StickyPost实例.
但是当我打电话时posts.sticky.build,它type被设定为StickyPost,但是课程仍然是Post.
posts.sticky.build
=> #<Post id: nil, message: nil, type: "StickyPost", created_at: nil, updated_at: nil>
Run Code Online (Sandbox Code Playgroud)
更新
显然这是有效的.
posts.sticky.build type: 'StickyPost'
=> #<StickyPost id: nil, message: nil, type: "StickyPost", created_at: nil, updated_at: nil>
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为范围已经设置了类型,所以看起来有点多余.在范围内设置此行为的任何方法?
我试图覆盖Devise的默认邮件程序来实现一些自定义功能.Devise正在发送电子邮件,但是有空白的身体.我剥夺了我的自定义邮件程序的所有功能,并尽可能使它成为裸骨,但无济于事.这是我的代码.
# config/initializers/devise.rb
config.mailer = DeviseMailer
# app/mailers/devise_mailer.rb
class DeviseMailer < Devise::Mailer
end
Run Code Online (Sandbox Code Playgroud) 我不知道我是如何描述这个问题的,起初我想展示我的模型,它维持下面的关系
category.rb
class Category < ApplicationRecord
has_many :job_categories, dependent: :destroy
has_many :jobs, through: :job_categories
end
Run Code Online (Sandbox Code Playgroud)
job.rb
class Job < ApplicationRecord
has_many :job_categories, dependent: :destroy
has_many :categories, through: :job_categories
end
Run Code Online (Sandbox Code Playgroud)
job_category.rb
class JobCategory < ApplicationRecord
belongs_to :category, counter_cache: :jobs_count
belongs_to :job
end
Run Code Online (Sandbox Code Playgroud)
schema.rb
create_table "categories", force: :cascade do |t|
t.string "name"
t.string "parent"
end
Run Code Online (Sandbox Code Playgroud)
这parent是一个维护集团的列,Technology与此类似的ruby,rails,programming技术相关.
以下是我按类别显示的查询
Category.select(:id, :name, :parent).group_by{|p| p.parent}
Run Code Online (Sandbox Code Playgroud)
它就像这样显示出来
技术
现在我想通过技术显示组中的所有作业,我对此有一个查询
Job.joins(:categories).where('lower(categories.parent) LIKE lower(?)', "%#{params[:parent]}%")
Run Code Online (Sandbox Code Playgroud)
并且它显示错误的输出,就像我只有一个类别,ruby,rails然后这一个作业显示两次,一个用于ruby,一个用于rails. …