草庐IT

line-through

全部标签

ruby-on-rails - Rails has_many :through saving additional fields

我正在尝试找到一种优雅的方式来保存约会模型(如下)中称为描述的附加字段。我的模型是这样设置的:classPhysician在我看来,我有复选框设置来保存连接表的数据,但我想滑入一个额外的“描述”字段以与连接一起保存。以下是我的看法:Patients 最佳答案 您可以使用accepts_nested_attributes_for来更新关联属性。在模型中:accepts_nested_attributes_for:appointments,:allow_destroy=>true在View中:引用http://api.rubyonrai

ruby-on-rails - Rails 类名称/类型不适用于多态 has_many :through

我有一个管理借方和贷方的发票系统。基本上,发票金额是通过其借方总和得出的,余额是通过将其贷方总和减去总金额得出的。我用四个模型来做这个。发票订单项借方信用它的工作方式是通过一个连接模型(行项目),该模型具有一个称为可记录的多态关联。乍一看一切似乎都正常工作。但是,检查行项目表明虽然recordable_id正常显示,但recordable_type为nil。下面是代码的分解:classInvoice:destroyhas_many:debits,:through=>:line_items,:as=>:recordablehas_many:credits,:through=>:line_

Ruby StringScanner 用于词法分析 : how to get the line number?

我正在使用StringScanner进行词法分析,如下所示:defnext@scanner.skip(/\s+/)value,kind=nil,nilTOKEN_DEF.each{|tok,regex|(kind=tok;break)if@scanner.scan(regex)}returnToken.new(kind,value,@line,@scanner.pos)end初步估计,这很好用,只是我不知道现在如何获取@line编号。我已经阅读了文档,begin_of_line在哪里?方法似乎合适,但我不知道如何使用它。 最佳答案

ruby-on-rails - 对于名称与复数相同的模型, `has_many, :through` 不在一个方向上工作

我正在构建一个应用程序来为StarWarsRPG生成角色。我添加了Species模型。Species既是单数又是复数,这让我陷入了一个循环。我可以通过使用species_index_path让路由在应用程序中正常工作,但由于某些原因,has_many:characteristics,:through=>:species_characteristics无法正常工作一个方向。例如,我有两个模型在控制台中正确播种(并工作):Characteristics和Species。Characteristics设置如下:classCharacteristic:species_characteristi

ruby - 安装 nokogiri 错误 : unrecognized command line option "-Wdivision-by-zero"

在osx10.9mavericks上运行geminstallnokogiri-v'1.6.1'获得:make"DESTDIR="cleanmake"DESTDIR="compilinghtml_document.ccc1:error:unrecognizedcommandlineoption"-Wdivision-by-zero"make:***[html_document.o]Error1makefailed,exitcode2 最佳答案 当我尝试在Mac10.9上安装nokogiri1.6.6.2时遇到了这个错误,我是这样修复的

ruby-on-rails - 使用 has_many :through 时如何访问 Rails 连接模型属性

我有一个类似这样的数据模型:#columnsincludecollection_item_id,collection_id,item_id,position,etcclassCollectionItem:collection_items,:source=>:collectionendclassCollection:positionhas_many:items,:through=>:collection_items,:source=>:item,:order=>:positionend一个项目可以出现在多个集合中,也可以在同一个集合中的不同位置出现不止一次。我正在尝试创建一个辅助方法来创

ruby-on-rails - 在 has_many :through association, 用 lambda 替换条件

我有这个关联:has_many:foo_participators,through::foos,source::user,conditions:"foos.state='completed'"Rails告诉我:DEPRECATIONWARNING:ThefollowingoptionsinyourBar.has_many:foo_participatorsdeclarationaredeprecated::conditions.Pleaseuseascopeblockinstead.Forexample,thefollowing:has_many:spam_comments,condi

ruby-on-rails - 自引用 has_many :through with customized :primary key issue

我正在尝试在我的Rails2.3.8应用程序(ruby1.8.7)中模拟twitter模型classConnection'subject_id',:primary_key=>'user_id',:class_name=>'User'belongs_to:follower,:foreign_key=>'follower_id',:primary_key=>'user_id',:class_name=>'User'endclassUser'user_id',:foreign_key=>'follower_id',:class_name=>'Connection'has_many:relat

ruby - rake/Rspec : How to suppress/quiet/silent the first output line showing the command with --pattern ?

问题:如果我运行ServerSpec(基于RSpec)到Rake使用以下命令之一:rakerakespecrakespec:allrakespec:bundleexecrake...Rake将它执行的命令打印到stdout在serverspec输出之前:/usr/bin/ruby1.9.1-I/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/lib:/var/lib/gems/1.9.1/gems/rspec-support-3.1.2/lib/var/lib/gems/1.9.1/gems/rspec-core-3.1.6/exe/rspec--pa

ruby-on-rails - Rails 3 查找所有关联记录 has_many :through

我想列出与某个特定类别和类(class)相关的所有帖子。我有:classPost:category_postshas_many:classroom_postshas_many:classrooms,:through=>:classroom_postsendclassCategory:category_postsendclassCategoryPost:classroom_postsendclassClassroomPost我想做这样的事Post.where(["category.id=?ANDclassroom.id=?",params[:category_id],params[:cl