Cannot access image_path in library class

25 views
Skip to first unread message

Martin Trummer

unread,
Oct 5, 2014, 12:48:03 PM10/5/14
to rubyonra...@googlegroups.com
Hi @ all,

In a rails application I have a nested module in my library:

module Foo
module Bar
def foo_bar
image_path("my_asset.png")
end
end
end

Within `foo_bar` i can use `image_path`, a rails helper, without any
problems. It finds the asset int the asset-pipeline and constructs the
path.

When I now add a class inside this module, I cannot access `image_path`,
and therefore my asset, anymore like shown in the following example:

module Foo
module Bar
class FooBar
def foo_bar
image_path("my_assset.png")
end
end
end
end

I get a `NoMethodError` as shown below.

NoMethodError - undefined method `image_url' for
#<Foo::Bar::FooBar:0x007fe279d08280>:

Why can't I access `image_path` anymore, or what changes do I need to
get this working?

Thanks in advance,
Martin

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

Clayton Cottingham

unread,
Oct 5, 2014, 1:01:19 PM10/5/14
to rubyonra...@googlegroups.com, Martin Trummer
Might be a typo? Your second code snippet has my_assset.png
Sent from my Android

Martin Trummer

unread,
Oct 5, 2014, 1:08:17 PM10/5/14
to rubyonra...@googlegroups.com
Sorry, it's not the typo. I changed the example.
Reply all
Reply to author
Forward
0 new messages