所以我使用的是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个标签
如果该标签恰好是股票报价,我如何使用帖子的:标签来访问股票报价?
现在,当我将 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 ?谢谢您的帮助。
当我尝试使用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)