开发者

Ruby object undefined method

开发者 https://www.devze.com 2023-03-28 00:31 出处:网络
I had this: class ProposalsController < ApplicationController def forkIt return \"FFFFFUUUU\" end end But when I tried to access the method (so I can gave my FFFFUUUU RAGE) it told me that suc

I had this:

class ProposalsController < ApplicationController
  def forkIt 

     return "FFFFFUUUU"
  end
end

But when I tried to access the method (so I can gave my FFFFUUUU RAGE) it told me that such method was undefined.

Now, I read somewhere that i needed to make it accessible, so this came

class ProposalsController < ApplicationController
   attr_accessor :forkIt
   def forkIt 
      return "FFFFFUUUU"
   end
end

This is the ruby console extract

ruby-1.9.2-p0 > @proposal = Proposal.find(4)
 => #<Proposal id: 4, title: "asda", descri开发者_运维问答ption: "fdsfds", owner: 1, parent_id: nil, created_at: "2011-08-12 21:28:39", updated_at: "2011-08-12 21:28:39"> 
ruby-1.9.2-p0 > @proposal.forkIt
NoMethodError: undefined method `forkIt' for #<Proposal:0x9b11030>

But still nothing... help this Ruby noob. thanks.


You defined your forkIt method on on your controller, ProposalsController, but you're calling it on the model, Proposal.

You need to move forkIt to the model class.

@proposal = Proposal.find(4) makes @propsal an instance of the Proposal class, not the ProposalControllers class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号