Calling render from a module

Ok, so, I'm trying to write my first gem to learn how it all works. Basically the gem would just be an extra view helper, so I want any methods in my module to be accessible in a rails app view.

I want my method to call render, and render a partial I have in my gem's app/views/shared folder. When I call "render", and run my rspec test I get an undefined method render for the rspec stuff. I've tried including ActionView::Base, and requiring it, and even tried just calling ActionView::Base.new.render :partial => 'shared/my_partial'. Calling it directly will call the render method, but I get a Missing partial error. Same thing happens if I call the full path to that partial.

My gem is structured like

MyGem -lib --my_gem.rb -app --views ---shared ----_my_partial.html.erb -spec ...

Thanks

~Jeremy

I took a look at how the Devise gem is doing it, but I don't see that they are actually calling the partial out. I'm assuming the views are just for the generator in that instance. I thought about just writing the HTML inside the method, but that feels hackish to me, plus, I would like to determine if the user is using haml, or erb, then render out a different partial depending.

I'm also open to ideas of a better way to do this. Again, this is just a learning experience for me, so I would like to know the best way to go about doing this.

Thanks!

~Jeremy

Ok, so, I'm trying to write my first gem to learn how it all works. Basically the gem would just be an extra view helper, so I want any methods in my module to be accessible in a rails app view.

I want my method to call render, and render a partial I have in my gem's app/views/shared folder. When I call "render", and run my rspec test I get an undefined method render for the rspec stuff. I've tried including ActionView::Base, and requiring it, and even tried just calling ActionView::Base.new.render :partial => 'shared/my_partial'. Calling it directly will call the render method, but I get a Missing partial error. Same thing happens if I call the full path to that partial.

rspec should realise that the code under test is a helper is the spec is in spec/helpers (and so should add the required stuff to the test environment that allows you to call actionviewy stuff.

Fred

Frederick Cheung wrote in post #983169:

Frederick Cheung wrote in post #983169:

>> Same thing happens if I call the full path to that partial. > rspec should realise that the code under test is a helper is the spec > is in spec/helpers (and so should add the required stuff to the test > environment that allows you to call actionviewy stuff.

> Fred

I'm sorry, I don't quite understand. Are you saying I should require all the ActionView stuff in my test? That might make the test pass, but when I go to use the actual gem in development, it would fail, wouldn't it?

No. I'm saying that if your spec file is in spec/helpers then rspec should assume that it's dealing with a view helper, and so will set up the test environment accordingly.

Fred