Tag: 嵌套

Rails嵌套with_option:如果用于validation

validate :updatable? # First validation there is with_options :if => Proc.new { |object| object.errors.empty? } do |updatable| updatable.with_options :if => “self.current_step == basic” do |step| validates …. bla-bla bla 因此,在进行任何validation之前,将调用可更新子例程,并使用适当的错误填充errors[:base]数组,这意味着该对象不可更新。 如果在此子例程中发现任何错误,我希望它跳过其余的validation,但上述示例不起作用 – 它执行所有validation。 但是,如果我改变:if => “self.current_step == basic” to :if => “self.errors.empty? && self.current_step == basic”就像魅力一样。 我做错了什么? 示例显示,嵌套with_option应该有效。 有人能帮我吗 ? 提前致谢。

在Ruby中重新打开嵌套模块exception

为什么重新打开嵌套模块会根据使用的语法给出不同的结果? 例如,这很好用: module A module E end end module A module E def Ee end end end 但是这个: module A module E end end module A::E def Ee end end 给出错误: reopen.rb:6:in `’: uninitialized constant A::E::E (NameError) from reopen.rb:5:in `’ (在有人指出这一点之前,解决方法是在定义Ee时使用self而不是模块名称,但这不是这篇文章的重点。)

在使用Ruby on Rails ActiveSupport :: Concernfunction时如何“嵌​​套”模块的包含?

我正在使用Ruby 1.9.2和Ruby on Rails v3.2.2 gem。 我希望“嵌套”包含模块,因为我使用的是RoR ActiveSupport :: Concernfunction,但我怀疑应该在哪里说明include方法。 也就是说,我有以下几点: module MyModuleA extend ActiveSupport::Concern # include MyModuleB included do # include MyModuleB end end 我应该在include MyModuleB的“body”/“context”/“scope”中声明包含MyModuleA还是应该在included do … end块中声明? 有什么区别,我应该从中得到什么?

在嵌套模型轨道中传递数组隐藏字段

我在视图中有以下代码: 30 %> 在控制台中传递的参数 Parameters: {“authenticity_token”=>”LJ/ZME2lHZ7VwCDgPKX6OFe326fXSXo5UB4M0cPwbCE=”, “esthour”=>{“rfp_id”=>”6”, “ecommerce_est_hours”=>””, “modul1hours”=>{“module_est_hours”=>”3”}, “designpages_est_hours”=>””, “cms_est_hours”=>””}, “modul1_ids”=>[“12”, “13”, “14”], “utf8″=>”✓”, “project_id”=>”second”, “commit”=>”Add Todo”} 当前用户:admin(id = 1) modul1_ids是基于创建三个文本框的隐藏数组,但是当我提交页面时,我给出了: ActionView::Template::Error (undefined method `merge’ for 12:Fixnum): 在第一个文本框中,我通过1秒2和第三个3 最后一个值(3)是一个人可以在控制台中看到的参数params module_est_hours”=>”3 ,但是rest的两个字段y没有通过什么,并且解决了错误的解决方案。 请帮我。 编辑1 30 %> 此代码不会给出错误,但值也不会存储在modul1hours表中 modul1hours表的字段是: integer :modul1_id decimal :module_est_hours decimal :module_act_hours integer :esthours_id ] .RB belongs_to:esthour attr_accessible:module_est_hours,:module_act_hours 和控制器 更新 def new @esthour […]

嵌套form_for奇异资源

我有一个像这样的单一嵌套资源: map.resources :bookings, :member => { :rate => :post } do |booking| booking.resource :review end 给我这些路线: new_booking_review GET /bookings/:booking_id/review/new(.:format) {:controller=>”reviews”, :action=>”new”} edit_booking_review GET /bookings/:booking_id/review/edit(.:format) {:controller=>”reviews”, :action=>”edit”} booking_review GET /bookings/:booking_id/review(.:format) {:controller=>”reviews”, :action=>”show”} PUT /bookings/:booking_id/review(.:format) {:controller=>”reviews”, :action=>”update”} DELETE /bookings/:booking_id/review(.:format) {:controller=>”reviews”, :action=>”destroy”} POST /bookings/:booking_id/review(.:format) {:controller=>”reviews”, :action=>”create”} 我试过这个: 哪个返回了这个错误: undefined method `booking_reviews_path’ for # 用我的评论控制器 def new @review = […]

将哈希转换为嵌套哈希

这个问题与这个问题相反。 给定一个散列,每个键都有一个数组 { [:a, :b, :c] => 1, [:a, :b, :d] => 2, [:a, :e] => 3, [:f] => 4, } 将它转换为嵌套哈希的最佳方法是什么? { :a => { :b => {:c => 1, :d => 2}, :e => 3, }, :f => 4, }