小编Joe*_*ith的帖子

使用stock_quote gem的股票报价作为acts_as_taggable gem的标签?

所以我使用的是acts_as_taggable gem提供的标签.帖子是我标记的内容.我怎么能说一些(pseduocode)=>

if a collection of Posts has a tag with a corresponding StockQuote, display the stock quote
Run Code Online (Sandbox Code Playgroud)

所以现在我有一个使用acts_as_taggable的Post资源.这是我的帖子索引操作现在的样子:

def index
@stock = StockQuote::Stock.quote("symbol")

if params[:tag]
@posts = Post.tagged_with(params[:tag])
else
 @posts = Post.order('cached_votes_score desc')
end

end
Run Code Online (Sandbox Code Playgroud)

所以我会以某种方式迭代所有@posts tagged_with params [:tag]并将标签与股票报价进行比较.如果匹配,则在所有@posts tagged_with params [:tag]的索引上显示引号.我将试着弄清楚如何限制每个帖子很快就有1个标签

如果该标签恰好是股票报价,我如何使用帖子的:标签来访问股票报价?

ruby ruby-on-rails

6
推荐指数
1
解决办法
435
查看次数

如何在 rails 控制台(撬)中将 admin 属性设置为 true?

现在,当我将 User.first.admin = false 更改为 User.first.admin = true 时,它​​不会保存。即使我之后运行 User.first.save 。如果我让

variable = User.first
variable.admin = true
variable.admin
Run Code Online (Sandbox Code Playgroud)

它将返回真(默认为假)

但是我的实际应用程序中的用户仍然没有获得如果 admin = true 的额外功能,那么我如何在 rails 控制台(使用 pry)为我的第一个用户正确设置 admin 为 true ?谢谢您的帮助。

ruby-on-rails ruby-on-rails-4

3
推荐指数
1
解决办法
2436
查看次数

PG :: ConnectionBad:致命错误:用户'用户名'错误导致对等身份验证失败

当我尝试使用User.connection或generic-table.connection连接到我的pg数据库时,我收到此错误

PG :: ConnectionBad:致命:用户'用户名'的对等身份验证失败

我仔细检查了我的database.yml,它看起来不错.我认为问题在于我的pg_bha.conf文件?我现在无法在我的应用程序或系统中找到此文件.

database.yml的

    development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username: 
  password:

 test: &TEST
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username: name
  password:

 production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username: name
  password:

 cucumber:
   <<: *TEST
  Thanks for the help.
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails

3
推荐指数
1
解决办法
6284
查看次数

标签 统计

ruby-on-rails ×3

postgresql ×1

ruby ×1

ruby-on-rails-4 ×1