Tag: actionviewhelper

Rails:在ActionView-Helper’collection_select’中预选值

我正在尝试让ActionView-Helper collection_select获取一个将在下拉菜单中预先选择的值。 两者都没有( :selected在html-option-hash中:selected ) @my_collection_object.id}) %> nor( :selected在选项 – 哈希中选择) @my_collection_object.id}, {}) %> 似乎工作。 我究竟做错了什么? 任何人都可以帮我这个吗?

Rails form_tag表单写入 – 具有非活动记录模型

我有点像Rails的新手。 我正在写一个couchrest-rails应用程序,所以我没有使用activerecord这个模型。 我只是想通了那就意味着 form_for(@model) 不行。 我正在尝试研究如何使用form_tag – 但大多数示例都不涉及new和create操作。 这是错的: New article :post do |f| %> 因为当我运行我的Cucumber场景时,我得到了这个: Scenario: Create Valid Article # features/article.feature:16 Given I have no articles # features/step_definitions /article_steps.rb:8 And I am on the list of articles # features/step_definitions/webrat_steps.rb:6 /home/deploy/www/www.trackingplace.com/app/ccc/app/views/articles/new.html.erb:3: warning: multiple values for a block parameter (0 for 1) from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.3/lib/action_view/helpers/capture_helper.rb:36 When I […]

Rails控制台 – 使用image_tag方法

如何在Rails控制台中执行image_tag方法 运行控制台$ rails c 加载助手 包括ActionView :: Helpers 执行命令 IMAGE_TAG( ‘test.png’) 我有一个奇怪的错误。 请帮忙!

如何在rails3中渲染图像选择

我想以图像作为选项在表单中呈现下拉列表。 如何在rails3中实现这一点?

如何在资产管道中包含ActionView助手?

如何包含资源管道执行上下文可以访问的Rails视图助手? 一个示例用例是使用form_tag帮助方法为表单生成标记,并使其可用于Javascript模板(如handlebars,jst等)。 我使用handlebar_assets gem,但这也适用于任何erb或haml模板。

如何为Rails的部分渲染查找添加视图路径?

我想拥有以下目录结构: views/ app1/ users/_user.html.erb users/index.html.erb app2/ users/index.html.erb shared/ users/_user.html.erb users/index.html.erb 在我看来,我打电话 # app1/users/index.html “user” %> # => /app1/users/_user.html.erb # app2/users/index.html “user” %> # => /shared/users/_user.html.erb 所以基本上,如何告诉Rails检查/ app2 / users dir然后检查共享目录,然后再提出它丢失了模板错误? 更新 我解决了这个问题(正如Senthil所建议的那样,使用File.exist? 这是我的解决方案 – 欢迎提供反馈和建议 # application_helper.rb # Checks for a partial in views/[vertical] before checking in views/shared def partial_or_default(path_name, options={}, &block) path_components = path_name.split(“/”) […]

RoR:nil的未定义方法`url_for’:NilClass

我有一个标准的Rails应用程序。 创建提示时,我想为每个对该提示感兴趣的用户创建一条消息。 这听起来很简单吧? 它应该是… 所以,我们从Tip Observer开始: class TipObserver < ActiveRecord::Observer def after_save(tip) # after the tip is saved, we'll create some messages to inform the users users = User.interested_in(tip) # get the relevant users users.each do |u| m = Message.new m.recipient = u link_to_tip = tip_path(tip) m.body = "Hello #{u.name}, a new tip: #{link_to_tip}" m.save! […]

如何在Rails之外的Ruby脚本中使用ActionView :: Helper?

我希望从Ruby脚本中使用ActionView :: Helpers :: NumberHelper。 我还需要什么等等?