草庐IT

associate_tag

全部标签

ruby-on-rails - :autosave property of has_many associations broken in Rails 2. 3.4?

在我将此作为错误发布给Rails团队之前,我想看看我是否做错了可能导致此行为的事情。具体来说,has_many关联的:autosave属性似乎没有按照文档工作。作为引用,这里是最新的API文档:http://api.rubyonrails.org/classes/Acti...ation.html查看“一对多示例”部分。我已经在测试应用程序中完全复制了代码,但它对我不起作用。具体来说,更新父对象,但不更新子对象。我的架构如下:create_table:postsdo|t|t.string:titlet.timestampsendcreate_table:commentsdo|t|t.t

ruby-on-rails - stylesheet_link_tag(:all) generates reference to `all.css` on Heroku

我的布局中有stylesheet_link_tag(:all)。即使在生产环境中运行它(railss-eproduction),它在本地机器上的表现也如预期。我所说的预期是指它发出所有指向现有样式表的链接,而不将它们连接到all.css中,并且它不发出指向all的链接。CSS.但是当我将它部署到Heroku时,结果是一样的,并且在开头添加了一个指向all.css的链接。这是我不想要也不期望的,尤其是当本地机器上的生产环境不发出它时。所以问题是如何在不手动指定所有文件的情况下摆脱Heroku上的all.css链接?谢谢。 最佳答案 H

ruby-on-rails - 如何使用连接表制作多模型 tag_cloud?

我有一个连接表create_table"combine_tags",force:truedo|t|t.integer"user_id"t.integer"habit_id"t.integer"valuation_id"t.integer"goal_id"t.integer"quantified_id"end其目的是让tag_cloud为多个模型工作。我把它放在application_controllerdeftag_cloud@tags=CombineTag.tag_counts_on(:tags)end我的tag_cloud看起来像这样:css_class%>#orthisdepen

ruby-on-rails - 对于新的 ActiveRecord 模型,为什么有些 has_many :through associations add a (1=0) predicate and distinct clause to the sql query?

每当我实例化一个新的ActiveRecord模型(一个尚未持久化到数据库中的模型)并尝试访问构建模型上的一些各种关联时,Rails查询构建器有时会:将(1=0)谓词添加到查询的where子句。在select语句中添加“distinct”子句。我认为这只会在has_many:through关联连接两个或多个表时发生。我想知道为什么它添加了(1=0)谓词以及distinct子句。对于(1=0)谓词,新模型是否已保存到数据库应该无关紧要(对吧?)。我不知道为什么要添加distinct子句。我在下面有一个简单的例子。classAssignment#s.assignment_attachment

ruby-on-rails - pg_search 使用 associated_against 给出错误 "column [model_name].[associated_column_name] does not exist"

我正在尝试使用pg_search来搜索关联模型。当我运行搜索时,出现错误“PG::Error:ERROR:columnplans.namedoesnotexist”。我正在“计划”模型中运行搜索,并尝试针对“地点”与列“名称”的关联进行搜索。连接这些的has_many:through模型是多态的。不知何故,sql查询将两者结合起来并抛出错误。我已经运行了associated_against迁移(railsgpg_search:migration:associated_against),搜索了文档,并寻找其他有错误的人,但一无所获,一定是我只是忽略了一些东西。如果我只是删除plan.rb

ruby-on-rails - 跳过 :touch associations when saving an ActiveRecord object

有没有办法在保存时跳过更新与:touch关联的关联?设置:classSchool我希望能够在跳过触摸的地方执行如下操作。@school=School.create@student=Student.create(school_id:@school.id)@student.name="Trevor"@student.save#CanIdothiswithouttouchingthe@schoolrecord?你能做到吗?像@student.save(skip_touch:true)这样的东西会很棒,但我还没有找到类似的东西。我不想使用像update_column这样的东西,因为我不想跳过A

ruby-on-rails - 没有命名路线的rails3中的远程form_tag

使这个实际异步发布的正确咒语是什么?form_tag:controller=>:magic,:action=>:search,:method=>post,:remote=>truedomethod=post和remote=true只是在url的末尾被压扁,而不是真正使它成为一个ajaxpost。 最佳答案 我发现唯一的方法是将url参数包装在url_for方法中。form_tagurl_for(:action=>:create,:id=>@artist.id),:remote=>truedo但是,如果您需要传递method参数,您可

ruby-on-rails - rails/事件记录 : save changes to a model's associated collections

我是否必须保存对模型集合中单个项目的修改,或者是否有一种方法可以在我保存模型时调用以保存它们。#save似乎没有这样做。例如:irb>rental=#...#=>#irb>rental.dvd#=>#,sale_price:#>irb>rental.dvd.copies+=1#=>21irb>rental.save#=>trueirb>rental.dvd#=>#,sale_price:#>irb>Dvd.find_by_title('TheWomenofSummer')#=>#,sale_price:#>在上面的例子中,租赁的DVD副本似乎没有更新数据库中的副本(注意不同的副本数)。

ruby-on-rails - haml_tag 直接输出到 Haml 模板

我的HAML模板的这个助手有什么问题?defdisplay_event(event)event=MultiJson.decode(event)markup_class=get_markup_class(event)haml_tag:li,:class=>markup_classdohaml_tag:b,"Foo"haml_tag:i,"Bar"endend这是错误:haml_tagoutputsdirectlytotheHamltemplate.Disregarditsreturnvalueandusethe-operator,orusecapture_hamltogetthevalu

ruby-on-rails - rails : Active Admin Association Image column

我是ruby​​onrails的新手,刚刚安装了activeadmin并尝试自定义观看次数。我有一个产品和图像表。每张图片属于一个产品。现在我想在显示产品页面时显示一个带有相关图像的列。目前只有image_url文本不起作用。稍后我想做让图片以50x50px显示。我该怎么做?(图片模型:名称:字符串image_url:文本)这是我所做的:ActiveAdmin.registerProductdoindexdocolumn"Image"do|image|image.image_urlendcolumn:namecolumn:preview_textcolumn:full_textcolu