Tag: view helpers

如何仅在返回> 0时显示link_to帮助程序

我有这个帮助链接 link_to “”, product_path(product, anchor: “disqus_thread”), data: { “disqus-identifier” => “#{url_for([product, {only_path: false}])}” }, class: “no-underline bold grey-text text-darken-3 margin-left” layout:application.rb %script{id: “dsq-count-scr”, src: “https://url.disqus.com/count.js”, async: “async”} _disqus.html.erb var disqus_shortname = ‘yourname’; var disqus_identifier = ”; var disqus_title = ”; var disqus_url = ”; (function() { // DON’T EDIT BELOW THIS LINE var d = […]

在coffeescript中获取rails视图辅助方法

我有一个助手,让我们说(为了简单起见) def call_alert return “alert ‘this should appear'” end 然后我有一个coffeescript文件some_test_page.js.coffee ,它呈现一个通过ajax调用的动作。 在some_test_page.js.coffee里面我有: 当我对/ some_test_page进行ajax调用时,我通常希望从coffeescript文件中获取已编译的javascript的响应,并且会发生警报。 但是,似乎无法访问我尝试使用的视图助手。 如果我把一个简单 alert ‘this should appear’ 在我的some_test_page.js.coffee文件中,它工作正常。 我觉得这应该没问题,但也许我正在做一些反常规或愚蠢的事情? 如何在我的coffeescript视图文件中从application_helper.rb获取视图助手?

Erubis阻止助手投掷错误与concat

我有几个块助手,这是我正在做的一个简单的例子: def wrap_foo foo, &block data = capture(&block) content = ” #{data} ” concat( content ) end 我只是在试用erubis而且它给了我以下错误: You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<< 删除对concat的调用会删除错误但最终导致我的包装器没有被渲染 使用: Rails 2.3.5 Erubis 2.6.5 并尝试了这个gem ,帮助Erubis(虽然2.6.4)和Rails 2.3一起发挥得更好

导轨4中未允许的参数

我读到了关于collection_check_boxes但我不明白如何设置选中的值。 我有以下型号: class Objective < ActiveRecord::Base has_many :indicators has_many :objective_children, class_name: "Objective", foreign_key: "parent_id" def objective_ids objective_children.collect{|o| o.id} end def objective_ids= objectives_ids objectives_ids.each do |id| objective_children << Objective.find(id) end end end 编辑视图: html复选框没问题,但我不知道如何将值设置为objective 。 我试过定义objective_ids= objectives_ids但没有任何反应。 在控制器中: class ObjectivesController < ApplicationController def objective_params params.require(:objective).permit(:name, :code, :description, :objective_ids) end end 编辑日志文件显示未Unpermitted parameters: perspective_id, objective_ids

Rails 3在Model中查看辅助方法

我的模型中有一个类方法,我需要从我的一个视图助手访问一个方法。 目前我include TalkHelper ,但我仍然得到NoM​​ethodError。

Rails 3.1:在客户端应用程序中公开引擎助手的更好方法

我找到了一些文章来解决引擎中的助手问题,这些问题不适用于消费(父)应用程序。 为了确保我们都在同一页上,让我们说我们有这个: module MyEngine module ImportantHelper def some_important_helper …do something important… end end end 如果您查看“隔离引擎的助手”(L293)中的rails引擎文档,它会说: # Sometimes you may want to isolate engine, but use helpers that are defined for it. # If you want to share just a few specific helpers you can add them to application’s # helpers in ApplicationController: # # class […]