Hi,

i want to know how to use method from model to be used in
controller like

sale.rb model

def list
# some stuff
end

employee controller

def show
@stamp = Sale.list
end


which shows me following error
undefined method `list'

how to over come this problem?

thanks,
-pab

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Peter Hickman at Oct 14, 2011 at 12:23 pm
    You are calling list as a class method so you need to define it as a
    class method

    def self.list
    # some stuff
    end

    or you need to call it as an instance method

    s = Sale.new
    @stamp = s.list

    or even

    @stamp = Sale.new.list
    On 14 October 2011 13:14, Pab wrote:
    Hi,

    i want to know how to use method from model to be used in
    controller like

    sale.rb model

    def list
    # some stuff
    end

    employee controller

    def show
    @stamp = Sale.list
    end


    which shows me following error
    undefined method `list'

    how to over come this problem?

    thanks,
    -pab

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Pab at Oct 14, 2011 at 1:35 pm
    hi,

    still same error comes
    undefined method 'list'

    thanks,
    -pab

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Oct 14, 2011 at 1:45 pm

    On 14 October 2011 14:35, Pab wrote:
    hi,

    still same error comes
    undefined method 'list'
    Show us the current code and the error please.

    Also please remember to quote the previous reply so we know what you
    are replying to.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Pab at Oct 14, 2011 at 1:57 pm
    hi,

    in employee controller

    def show
    @stamp=Sale.new.list
    end

    in sale.rb model i am using

    def self.list
    @list=Sale.find(:all)
    return @list
    end

    its shows following error
    undefined method 'list'

    thanks,
    -pab

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Tim Shaffer at Oct 14, 2011 at 2:19 pm
    Now you have the opposite problem... You are now calling list as an instance
    method and you have it defined as a class method.

    You need to do ONE of the following.

    Define it as a class method, and call it as a class method:

    def self.list
    code
    end

    @list = Sale.list

    Define it as an instance method and call it as an instance method:

    def list
    code
    end

    @list = Sale.new.list

    However, based on what the list method does, it's probably best that you do
    the former and have it be a class method.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/BaQUoI1plSUJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Pab at Oct 17, 2011 at 12:06 pm
    @Tim thanks for your help, your idea works fine

    thanks,
    -pab

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Fahim patel at Oct 6, 2012 at 12:28 pm

    Pab wrote in post #1027023:
    @Tim thanks for your help, your idea works fine

    thanks,
    -pab
    Thanks u all

    Regards

    Fahim Babar Patel

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 14, '11 at 12:14p
activeOct 6, '12 at 12:28p
posts8
users5
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase