jjzjj

instance_variable_names

全部标签

ruby-on-rails - rails : Using CanCan to define multiple roles depending on instances of single Model?

我目前一直在研究如何根据我们想要的每个条件来分离CanCan的角色。在我们的应用程序中,有很多类别(例如数学、英语、历史等),每个类别中都有很多类(class)。每个用户可以在每个类别中扮演许多不同的角色。例如,约翰可以是数学的“读者”,这意味着他可以阅读所有数学类(class)。约翰也可以是英语的“作家”,这意味着他可以阅读所有英语类(class),在类别英语中创建类(class),并仅编辑/删除他创建的英语类(class)。如果这些是John仅有的角色,他将无法在导航栏中看到类别历史记录,并且将被拒绝访问历史记录中的类(class)。这些是关系的建立方式:classUser在mod

ruby-on-rails - pg_search 使用 associated_against 给出错误 "column [model_name].[associated_column_name] does not exist"

我正在尝试使用pg_search来搜索关联模型。当我运行搜索时,出现错误“PG::Error:ERROR:columnplans.namedoesnotexist”。我正在“计划”模型中运行搜索,并尝试针对“地点”与列“名称”的关联进行搜索。连接这些的has_many:through模型是多态的。不知何故,sql查询将两者结合起来并抛出错误。我已经运行了associated_against迁移(railsgpg_search:migration:associated_against),搜索了文档,并寻找其他有错误的人,但一无所获,一定是我只是忽略了一些东西。如果我只是删除plan.rb

ruby - instance_eval 的 block 参数 - 记录了吗?目的?

刚刚意识到instance_eval产生self作为关联block的参数(除了1.9.2版本中的错误:http://www.ruby-forum.com/topic/189422)1.9.3p194:003>classC;end1.9.3p194:004>C.new.instance_eval{|*a|a}=>[#]1.9.3p194:005>这是否在某处记录/规范?看着ruby-doc:BasicObject,看不到提到的任何block参数。除了一些纯粹的历史原因之外,是否还有其他原因明确地传递它,而它自己总是被定义?我被这个击中的方式是:l=lambda{}myobj.instan

ruby-on-rails - 处理 undefined variable

我在一个View中渲染局部:@video,:video_id=>'video_show_id'%>并在部分中包含此代码:"oembed",:id=>video_id%>"oembed"%>问题是这个部分在我的应用程序中的许多地方呈现,并且在那些其他View中我不想将:video_id传递到部分。因此,我的应用会抛出一个错误,指出video_id未定义。我可以将:video_id=>""传递到其他View中的部分,但由于部分在许多地方呈现,这有点痛苦。有没有更简单的方法来处理这个问题? 最佳答案 尝试defined?并不是说​​它真的

ruby-on-rails - Rails 型号 : Name -- First, 最后

我是Rails的新手,正在为用户开发一个带有Profile模型的Rails3应用。在配置文件模型中,我希望有一个“名称”条目,并且我希望能够使用简单的语法访问它的逻辑变体,例如:user.profile.name="JohnDoe"user.profile.name.first="John"user.profile.name.last="Doe"这可能吗,还是我需要坚持使用“first_name”和“last_name”作为我在这个模型中的字段? 最佳答案 有可能,但我不推荐。如果我是你,我会坚持使用first_name和last_

ruby-on-rails - RSpec::Mocks::ExampleMethods 的未定义方法 instance_double

我有一个这样的测试用例:describeWorkCardsControllerdoit"something"dowork_card=instance_double(WorkCard,{:started?=>true})#somemorecodeendend当我运行RSpec时,出现错误:undefinedmethod'instance_double'for#根据http://rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/ExampleMethods这种方法存在。所以我尝试通过以下方式直接访问它:describeWorkCardsCo

ruby - 可能对 curry 过程进行 instance_eval 吗?

假设我有这样一个类:classTestdeftest_func140endend还有一个proc,它引用了Test中的一个成员函数:p=->(x,y){x+y+test_func}#=>#要调用p,我将它绑定(bind)到Test的一个实例:test=Test.new#=>#test.instance_exec(1,2,&p)#=>143现在假设我只想将y传递给p,并且始终传递x=1:curried=p.curry[1]#=>#理想情况下,我应该能够像以前一样instance_exec,但是:test.instance_exec(2,&curried)=>NameError:undef

ruby-on-rails - AASM 不适用于我的 rails 3 和 ruby​​ 1.8.7(未定义方法 `name' 为 nil :NilClass )

我正在使用Rails3.2.2,带有aasmgem,我有这样的Document模型:classDocumenttruestate:readstate:closedevent:viewdotransitions:to=>:read,:from=>[:unread]endevent:closedotransitions:to=>:closed,:from=>[:read,:unread]endend现在在我的控制台上:➜✗bundleexecrailscLoadingdevelopmentenvironment(Rails3.2.2)irb(main):006:0>Document.cre

ruby - 我可以将一个本身需要一个 block 的 block 传递给 ruby​​ 中的 instance_exec 吗?

我期待代码foo=proc{puts"foo"}instance_exec(1,2,3,&foo)do|*args,&block|puts*argsblock.callputs"bar"end输出123foobar但是报错bothblockargandactualblockgiven我可以将一个本身需要一个block的block传递给ruby​​中的instance_exec吗? 最佳答案 &foo尝试将foo作为block传递给instance_exec,而您已经传递了一个显式block。省略与号发送foo就像任何其他参数一样(除

ruby - 模块嵌套在 instance_eval/exec 或 module_eval/exec 中

我在尝试回答this时想到了这个问题.以下是预期的行为:moduleApModule.nestingend#=>[A]但是以下内容:A.instance_eval{pModule.nesting}A.instance_exec{pModule.nesting}A.module_eval{pModule.nesting}A.module_exec{pModule.nesting}全部返回[]。为什么这些不能像上面那样工作?附加问题Muistooshort提出了一个有趣的观点。如果这是正确的,那么Module.nesting将是依赖于文字上下文的方法和变量之一,例如Method#sourc