accessing model methods in views

0 views
Skip to first unread message

Ming

unread,
Dec 3, 2009, 2:34:18 PM12/3/09
to merb
class Catalog
include DataMapper::Resource

storage_names[:default] = 'main'

property :id, Integer, :field => 'code', :key => true
property :item, Text

has n, :subcatalogs

def slug
"whatever"
end
end

if i try to call slug in a view, where c is an instance of Catalog,

c.slug

yields an undefined method error.

Yet c.id and c.item access just fine.

Tony Mann

unread,
Dec 3, 2009, 2:52:38 PM12/3/09
to me...@googlegroups.com
This seems impossible. You will need to post your view code so we can see it.

..tony..


--

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



Ming

unread,
Dec 3, 2009, 5:35:18 PM12/3/09
to merb
OK. I ran the debugger and figured out the problem, which unless I
misunderstand, is not correct behavior.

in the view index.haml.html,

the assignment,

- x = c.slug

then the use of x,

= url(:catalog, x)

works fine

BUT, direct use of the method call,

url(:catalog, c.slug)

produces a undefined method error.

On Dec 3, 2:52 pm, Tony Mann <thephatm...@gmail.com> wrote:
> This seems impossible. You will need to post your view code so we can see
> it.
>
> ..tony..
>
>
>
> On Thu, Dec 3, 2009 at 11:34 AM, Ming <min...@gmail.com> wrote:
> > class Catalog
> >  include DataMapper::Resource
>
> >  storage_names[:default] = 'main'
>
> >  property :id, Integer, :field => 'code', :key => true
> >  property :item, Text
>
> >  has n, :subcatalogs
>
> >  def slug
> >      "whatever"
> >  end
> > end
>
> > if i try to call slug in a view, where c is an instance of Catalog,
>
> > c.slug
>
> > yields an undefined method error.
>
> > Yet c.id and c.item access just fine.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "merb" group.
> > To post to this group, send email to me...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > merb+uns...@googlegroups.com <merb%2Bunsu...@googlegroups.com>.

Tony Mann

unread,
Dec 3, 2009, 7:33:28 PM12/3/09
to me...@googlegroups.com
Can you send your view code and your controller code? The snippets are not enough.

..tony..

To unsubscribe from this group, send email to merb+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages