我的网站指定了多个og:image标签,我想控制哪一个是默认值.它是否与指定顺序有关?
现在,图像以#3,#1,#2(默认为#3)的顺序出现在链接帖子选择器中,这似乎很不寻常.
感谢您提供的任何见解.
我的Rails应用程序中有一个非常简单的(我认为)单表继承(STI)设置.
有一个带有嵌套资源Post的User模型.使用STI,我有它,以便一些帖子可以是Post :: Urgent对象.
我注意到我的URL帮助程序<%= [@user, @post] %>需要硬编码,<%= user_post_path[@user, @post] %>否则我最终会看到有关Rails没有找到user_post_urgent_path方法的错误.好的,这相当容易.
(这样做的另一种方法也是<%= [@user, post: @post] %>.)
好吧,由于某种原因,我无法弄清楚如何以form_for相同的方式调整方法.当我写简单的时候
<%= form_for [@user, @post] do |f| %>
Run Code Online (Sandbox Code Playgroud)
,我在URL帮助器案例中得到了类似的错误,但是在表单上下文中:undefined method 'user_post_urgen_path'.
我通过指定:
<%= form_for [@user, @post], url: :user_post do |f| %>
Run Code Online (Sandbox Code Playgroud)
但这并不完全有效,因为当我提交表单时,我在控制器中遇到问题,说强参数行params.require(:post)失败:
param is missing or the value is empty: post
Run Code Online (Sandbox Code Playgroud)
如果我检查,params我发现表单正在传递一个post_urgent对象,而不是一个post对象.
当然,我可以手动输入一些总是说的逻辑if !params[:post] and params[:post_urgent], then params[:post] = params[:post_urgent].但是,这似乎只是方式太哈克,尤其是对Rails的. …
forms inheritance ruby-on-rails polymorphic-associations sti
我有一个user.rb模型,我在其中定义了一个范围admins,即通过权限表具有admin角色的用户.
has_many :permissions
has_many :roles, :through => :permissions
Run Code Online (Sandbox Code Playgroud)
范围的工作方式如下:
scope :admins, joins(:permissions).merge(Permission.admin_permissions)
Run Code Online (Sandbox Code Playgroud)
我还想制作一个名为non-admins或类似的范围,这是所有没有管理员角色的用户.
最简单的方法是什么?
多年来我一直使用RVM作为我的Ruby版本管理器,但我想切换到rbenv以简化它.但是我发现部署有些奇怪的问题.这里似乎出错了:
# env RBENV_ROOT=\"/home/deploy/.rbenv\" PATH=\"/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH\" /home/deploy/.rbenv/bin/rbenv exec bundle install --gemfile /domains/myapp.com/releases/20140119013611/Gemfile --path /domains/myapp.com/shared/bundle --deployment --without development test
> rbenv: bundle: command not found
> The `bundle' command exists in these Ruby versions:
> 2.0.0-p353
Run Code Online (Sandbox Code Playgroud)
好的,所以我指定了我想要的rbenv版本 -
# env RBENV_ROOT=\"/home/deploy/.rbenv\" PATH=\"/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH\" RBENV_VERSION=\"2.0.0-p353\" /home/deploy/.rbenv/bin/rbenv exec bundle install --gemfile /domains/myapp.com/releases/20140119013611/Gemfile --path /domains/myapp.com/shared/bundle --deployment --without development test
> rbenv: version `"2.0.0-p353"' is not installed
Run Code Online (Sandbox Code Playgroud)
呵呵.那真是怪了.
# rbenv versions
> system
> * 2.0.0-p353 (set by /home/deploy/.rbenv/version)
Run Code Online (Sandbox Code Playgroud)
知道我哪里错了吗?该bundle install命令似乎认为2.0.0-p353不存在,但rbenv versions …
我注意到Rails(4.1)ActiveRecord有些奇怪,在哪里select,count有时混合不好:
User.all.count
=> 103
User.all.size
=> 103
User.all.length
=> 103
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.我可以选择id:
User.select(:id).all.count
=> 103
User.select(:id).all.size
=> 103
User.select(:id).all.length
=> 103
Run Code Online (Sandbox Code Playgroud)
还好.我也可以选择email:
User.select(:email).all.count
=> 103
User.select(:email).all.size
=> 103
User.select(:email).all.length
=> 103
Run Code Online (Sandbox Code Playgroud)
但现在问题开始了.当我选择上都 id和email:
User.select(:id, :email).all.count
(0.4ms) SELECT COUNT(id, email) FROM `users`
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' email) …Run Code Online (Sandbox Code Playgroud) sql activerecord ruby-on-rails ruby-on-rails-4 ruby-on-rails-4.1
我已经在网上看到大量关于python NLTK如何使计算bigrams单词变得容易的文档.
信件怎么样?
我想要做的是插入字典并让它告诉我不同字母对的相对频率.
最终,我想制作一些马尔可夫过程,以产生看起来很可能(但是假的)单词.
我有一个莫名其妙的困难时间让我的命名路线在我的rspec测试中工作.
这就是我所看到的:
1) Home GET / works!
Failure/Error: get root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe13b0c1538>
# ./spec/requests/home_spec.rb:6:in `block (3 levels) in <top (required)>'
2) Home GET / shows products!
Failure/Error: get products_path
NameError:
undefined local variable or method `products_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fe13b0cdea0>
# ./spec/requests/home_spec.rb:10:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
require 'spec_helper'
describe "Home" do
describe "GET /" do
it "works!" do
get root_path
response.status.should be(200)
end
it "shows products!" do
get products_path
response.status.should be(200) …Run Code Online (Sandbox Code Playgroud) 我在使用Capistrano将Whenever gem部署到我的生产环境时遇到了问题.
问题源于一个bundle exec whenever触发一些"缺少宝石"问题的命令(但是从shell运行bundle install表明事实上已经存在!).
我的感觉是发生了两件事之一:Bundler在bundle exec被调用之前没有完全加载,或者某种程度上存在一个在错误的地方运行它的路径问题.
这是发生了什么:
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git@my-source-repository:mysource.git HEAD"
command finished in 1847ms
* executing "git clone -q git@my-source-repository:mysource.git /domains/myapp/releases/20130124211036 && cd /domains/myapp/releases/20130124211036 && git checkout -q -b deploy 90238bbcb993e3e7df2374ffaa13e7ed701c202e && (echo 90238bbcb993e3e7df2374ffaa13e7ed701c202e > /domains/myapp/releases/20130124211036/REVISION)"
servers: ["myip"]
[myip] executing command
** [myip :: out] Enter passphrase for key '/home/deploy/.ssh/id_rsa':
** [myip :: out]
command finished in 9294ms
* …Run Code Online (Sandbox Code Playgroud) 我已经遇到了一些在多个站点共享的页脚缓存问题,我想知道可能会出现什么问题.这是错误消息和回溯:
Cache read: remote_footer_information ({:expires_in=>300 seconds})
Cache generate: remote_footer_information ({:expires_in=>300 seconds})
Cache write: remote_footer_information ({:expires_in=>300 seconds})
Marshalling error for key 'remote_footer_information': no _dump_data is defined for class Proc
You are trying to cache a Ruby object which cannot be serialized to memcached.
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/server.rb:397:in `dump'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/server.rb:397:in `serialize'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/server.rb:269:in `set'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/server.rb:60:in `request'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/options.rb:18:in `block in request'
/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/options.rb:17:in `request'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:348:in `perform'
/app/vendor/bundle/ruby/1.9.1/gems/dalli-2.6.4/lib/dalli/client.rb:199:in `set'
(eval):7:in `block in set_with_newrelic_trace'
...
Run Code Online (Sandbox Code Playgroud)
这是定义缓存检索的位置:
require 'httparty'
module Myclassname
class Footer
include HTTParty
format :json
attr_accessor :response …Run Code Online (Sandbox Code Playgroud) 我有一个时间在Ubuntu 12.04上安装Nokogiri的魔鬼.我用rbenv.
$ gem install nokogiri -v '1.6.1'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.1/.autotest
$ sudo gem install nokogiri -v '1.6.1'
ERROR: Error installing nokogiri:
nokogiri requires Ruby version >= 1.9.2.
$ rbenv sudo gem install nokogiri -v '1.6.1'
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/home/deploy/.rbenv/versions/2.0.0-p353/bin/ruby extconf.rb
Gem files will remain installed in /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /home/deploy/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out
$ ruby -v …Run Code Online (Sandbox Code Playgroud) ruby ×3
activerecord ×2
bundler ×2
capistrano ×2
rbenv ×2
caching ×1
dalli ×1
facebook ×1
forms ×1
inheritance ×1
n-gram ×1
named-scope ×1
nlp ×1
nltk ×1
nokogiri ×1
opengraph ×1
python ×1
rspec ×1
rubygems ×1
scope ×1
sql ×1
sti ×1
ubuntu-12.04 ×1
whenever ×1