草庐IT

nested_category

全部标签

ruby-on-rails - Prawn PDF : I need to generate nested tables

我需要一个表,其中行实际上是2行表,一个嵌套表是..我怎样才能在Prawn中做到这一点?也许我需要延期..但哪一个? 最佳答案 现在支持子表:Prawn::Document.generate("subtable.pdf")do|pdf|subtable=pdf.make_table([["sub"],["table"]])pdf.table([[subtable,"original"]])end 关于ruby-on-rails-PrawnPDF:Ineedtogeneratenested

ruby-on-rails - 在 Rails 中使用 accepts_nested_attributes_for + 批量赋值保护

假设你有这个结构:classHouse请注意,Tv的用户是故意不可访问的。所以你有一个三层嵌套的表单,允许你在一个页面上输入房子、房间和电视。这是Controller的创建方法:defcreate@house=House.new(params[:house])if@house.save#...standardstuffelse#...standardstuffendend问题:您究竟如何为每台电视填充user_id(它应该来自current_user.id)?什么是好的做法?这是我在其中看到的catch22。将user_ids直接填充到params散列中(它们嵌套得很深)保存将失败,因

ruby-on-rails - 为什么我的 helper 递归方法不返回每个值?

我想显示一个由gem祖先管理的类别树。我想使用一个助手,它会递归地遍历树并一个一个地返回类别,暂时没有html标签或内容。moduleCategoriesHelperdefdisplay_tree(category)ifcategory.has_children?category.children.eachdo|sub_category|display_tree(sub_category)puts(sub_category.name)#tocheckifitgoeshereendendcategory.nameendendcategory参数是根类别之一。它应该返回什么?在网页中:它仅

ruby-on-rails - 如何在 RubyOnRails 中使用 'acts as nested set' 创建一个可排序的接口(interface)

我一直在为使用acts_as_list的模型实现一些不错的交互界面,这些界面可以对我的mRails应用程序中的列表进行排序。我有一个排序函数,在每次拖放之后使用sortable_elementscript.aculo.us函数调用并设置每条记录的位置。这是在拖放完成后处理排序的Controller操作示例:defsortparams[:documents].each_with_indexdo|id,index|Document.update_all(['position=?',index+1],['id=?',id])endend现在我正在尝试对嵌套集模型(acts_as_nested

ruby-on-rails - rails : route helpers for nested resources

我有如下嵌套资源:resources:categoriesdoresources:productsend根据RailsGuides,Youcanalsouseurl_forwithasetofobjects,andRailswillautomaticallydeterminewhichrouteyouwant:Inthiscase,Railswillseethat@magazineisaMagazineand@adisanAdandwillthereforeusethemagazine_ad_pathhelper.Inhelperslikelink_to,youcanspecifyju

ruby - Haml "Illegal Nesting"问题;如何在同一个标​​签中放置多个代码元素?

-@subjects.eachdo|s|%tr%td=s.position%td=s.name%td=s.visible?"Yes":"No"%td=s.pages.size%td=link_to("Show",{:action=>"show",:id=>s.id},:class=>"actionshow")=link_to("Edit",{:action=>"edit",:id=>s.id},:class=>"actionedit")=link_to("Delete",{:action=>"delete",:id=>s.id},:class=>"actiondelete")错误消息:

ruby-on-rails - Rails 路由 : Nested, 成员、集合、命名空间、范围和可定制

我想了解更多关于Rails路线的信息。成员和收藏#Exampleresourceroutewithoptions:resources:productsdomemberdoget'short'post'toggle'endcollectiondoget'sold'endend命名空间和作用域#Exampleresourceroutewithinanamespace:namespace:admindoresources:productsendscope:admindoresources:productsend约束,Redirect_to#Exampleresourceroutewithop

ruby-on-rails - 如何在使用 Ruby on Rails ActiveSupport::Concern 功能时包含模块 "nest"?

我正在使用Ruby1.9.2和RubyonRailsv3.2.2gem。我想“嵌套”模块的包含,因为我正在使用RoRActiveSupport::Concern功能,但我怀疑我应该在哪里声明include方法。也就是说,我有以下内容:moduleMyModuleAextendActiveSupport::Concern#includeMyModuleBincludeddo#includeMyModuleBendend应该我在MyModuleA的“正文”/“上下文”/“范围”中声明includeMyModuleB或者我应该声明包含的do...endblock?有什么区别,我应该从中得到什

ruby-on-rails - 获取类别和子类别的所有产品(rails,awesome_nested_set)

我正在开发一个电子商务应用程序,试图解决以下问题:我通过awesome_nested_set插件实现了我的类别。如果我通过选择一个类别列出我的文章,一切正常,但对于某些链接,我想显示一个类别的所有产品及其子类别的产品。这里是仅适用于一个类别的Controller代码:#products_controller.rbdefindexifparams[:category]@category=Category.find(params[:category])#@products=@category.product_list@products=@category.productselse@cate

Ruby 哈希错误 : undefined method [] when attempting to set deeply nested keys

我有一段代码是这样的:my_hash={}first_key=1second_key=2third_key=3my_hash[first_key][second_key][third_key]=100ruby解释器给了我一个错误:undefinedmethod`[]'fornil:NilClass(NoMethodError)那么这是否意味着我不能那样使用哈希?还是您认为此错误可能是其他原因造成的? 最佳答案 哈希默认不嵌套。由于my_hash[first_key]未设置任何值,因此它是nil。并且nil不是散列,因此尝试访问其中一