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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 21, 3:39 am, Jeremy Woertink <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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> > My gem is structured like > > MyGem > -lib > --my_gem.rb > -app > --views > ---shared > ----_my_partial.html.erb > -spec > ... > > Thanks > > ~Jeremy > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Frederick Cheung wrote in post #983169:> On Feb 21, 3:39am, Jeremy Woertink <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> 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. > > FredI''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? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 22, 9:52 pm, Jeremy Woertink <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote in post #983169: > > > On Feb 21, 3:39am, Jeremy Woertink <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> 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> -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.