Weston Platter
2012-Dec-01 23:19 UTC
Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
Working on Rails Engine. I want to make the controllers customizable whereever the Rails Engine is used. Therefore, I was trying to use `extend ActiveSupport::Concern` on the Engine controller class and include it in MyRailsApp. https://gist.github.com/4185823 # code in my rails engine moduel MyEngine class SomeController extend ActiveSupport::Concern def engine_some_method end end end # code in my rails app where engine is implemented class SomeController include MyEngine::SomeController def app_some_method end # code that''s available by including the Rails Engine code # def engine_some_method # end end But, this breaks my rpsec controller tests because of an undefined "recycle" method. 12) Qe::Admin::QuestionPagesController POST reorder Failure/Error: xhr :post, :create, NoMethodError: undefined method `recycle!'' for #<Qe::Admin::QuestionPagesController:0x007f80aa1c7528> # ./spec/controllers/admin/pages_controller_spec.rb:69:in `block (2 levels) in <top (required)>'' When I comment out the "include MyEngine::Controller" everything passes. Why? -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ViCnX2HqSPkJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-02 01:11 UTC
Re: Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
On Dec 1, 7:19 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > But, this breaks my rpsec controller tests because of an undefined > "recycle" method. > > 12) Qe::Admin::QuestionPagesController POST reorder > Failure/Error: xhr :post, :create, > NoMethodError: > undefined method `recycle!'' for > #<Qe::Admin::QuestionPagesController:0x007f80aa1c7528> > # ./spec/controllers/admin/pages_controller_spec.rb:69:in `block (2 > levels) in <top (required)>'' > > When I comment out the "include MyEngine::Controller" everything passes. >If it''s commenting out the include that fixes things, why are you so sure that it''s the extend at fault rather than something else in the module? Personally I''d be inclined to thing that by including your module you''re accidentally shadowing an existing method on the controller - if you were to show a minimal example that reproduces the problem rather than dummy code someone might be able to have a guess (I suspect the issue may have been lost in translation from your actual code to the example you gave since the latter isn''t valid ruby (for example you''re including a class rather than a module) Fred> Why?-- 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 https://groups.google.com/groups/opt_out.
Weston Platter
2012-Dec-02 23:22 UTC
Re: Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
What you said makes sense. I incorrectly said I commented out include MyEngine::SomeController when I meant to say commenting out extend ActiveSupport::Concern fixes the issue. The codeabse is here, https://github.com/twinge/questionnaire_engine/tree/8836c2a3b92e676ead4653d11696eb182b63746e . The specific Controller Class is here, https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ead4653d11696eb182b63746e/app/controllers/qe/admin/elements_controller.rb The specific Controller Spec test is here, https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ead4653d11696eb182b63746e/spec/controllers/admin/elements_controller_spec.rb On Saturday, December 1, 2012 7:11:02 PM UTC-6, Frederick Cheung wrote:> > > > On Dec 1, 7:19 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > But, this breaks my rpsec controller tests because of an undefined > > "recycle" method. > > > > 12) Qe::Admin::QuestionPagesController POST reorder > > Failure/Error: xhr :post, :create, > > NoMethodError: > > undefined method `recycle!'' for > > #<Qe::Admin::QuestionPagesController:0x007f80aa1c7528> > > # ./spec/controllers/admin/pages_controller_spec.rb:69:in `block (2 > > levels) in <top (required)>'' > > > > When I comment out the "include MyEngine::Controller" everything passes. > > > > If it''s commenting out the include that fixes things, why are you so > sure that it''s the extend at fault rather than something else in the > module? Personally I''d be inclined to thing that by including your > module you''re accidentally shadowing an existing method on the > controller - if you were to show a minimal example that reproduces the > problem rather than dummy code someone might be able to have a guess > (I suspect the issue may have been lost in translation from your > actual code to the example you gave since the latter isn''t valid ruby > (for example you''re including a class rather than a module) > > Fred > > Why? >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ZV0oMRfctjgJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-03 01:00 UTC
Re: Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
On Dec 2, 7:22 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What you said makes sense. > > I incorrectly said I commented out > include MyEngine::SomeController > > when I meant to say commenting out > extend ActiveSupport::Concern >Calling extend activesupport::concern on a controller sounds like a weird thing to do - it''s supposed to be used on modules. What were you trying to do with it? Fred> fixes the issue. > > The codeabse is here,https://github.com/twinge/questionnaire_engine/tree/8836c2a3b92e676ea... > . > > The specific Controller Class is here,https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ea... > > The specific Controller Spec test is here,https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ea... > > > > > > > > On Saturday, December 1, 2012 7:11:02 PM UTC-6, Frederick Cheung wrote: > > > On Dec 1, 7:19 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > But, this breaks my rpsec controller tests because of an undefined > > > "recycle" method. > > > > 12) Qe::Admin::QuestionPagesController POST reorder > > > Failure/Error: xhr :post, :create, > > > NoMethodError: > > > undefined method `recycle!'' for > > > #<Qe::Admin::QuestionPagesController:0x007f80aa1c7528> > > > # ./spec/controllers/admin/pages_controller_spec.rb:69:in `block (2 > > > levels) in <top (required)>'' > > > > When I comment out the "include MyEngine::Controller" everything passes. > > > If it''s commenting out the include that fixes things, why are you so > > sure that it''s the extend at fault rather than something else in the > > module? Personally I''d be inclined to thing that by including your > > module you''re accidentally shadowing an existing method on the > > controller - if you were to show a minimal example that reproduces the > > problem rather than dummy code someone might be able to have a guess > > (I suspect the issue may have been lost in translation from your > > actual code to the example you gave since the latter isn''t valid ruby > > (for example you''re including a class rather than a module) > > > Fred > > > Why?-- 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 https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-03 01:06 UTC
Re: Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
On Dec 2, 9:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 2, 7:22 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What you said makes sense. > > > I incorrectly said I commented out > > include MyEngine::SomeController > > > when I meant to say commenting out > > extend ActiveSupport::Concern > > Calling extend activesupport::concern on a controller sounds like a > weird thing to do > - it''s supposed to be used on modules. What were you trying to do > with it?And I assume that the reason this causes a problem is something to do with how as::concern changes the behaviour of include so as to setup module dependencies. Fred> > > > > > > > > fixes the issue. > > > The codeabse is here,https://github.com/twinge/questionnaire_engine/tree/8836c2a3b92e676ea... > > . > > > The specific Controller Class is here,https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ea... > > > The specific Controller Spec test is here,https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ea... > > > On Saturday, December 1, 2012 7:11:02 PM UTC-6, Frederick Cheung wrote: > > > > On Dec 1, 7:19 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > But, this breaks my rpsec controller tests because of an undefined > > > > "recycle" method. > > > > > 12) Qe::Admin::QuestionPagesController POST reorder > > > > Failure/Error: xhr :post, :create, > > > > NoMethodError: > > > > undefined method `recycle!'' for > > > > #<Qe::Admin::QuestionPagesController:0x007f80aa1c7528> > > > > # ./spec/controllers/admin/pages_controller_spec.rb:69:in `block (2 > > > > levels) in <top (required)>'' > > > > > When I comment out the "include MyEngine::Controller" everything passes. > > > > If it''s commenting out the include that fixes things, why are you so > > > sure that it''s the extend at fault rather than something else in the > > > module? Personally I''d be inclined to thing that by including your > > > module you''re accidentally shadowing an existing method on the > > > controller - if you were to show a minimal example that reproduces the > > > problem rather than dummy code someone might be able to have a guess > > > (I suspect the issue may have been lost in translation from your > > > actual code to the example you gave since the latter isn''t valid ruby > > > (for example you''re including a class rather than a module) > > > > Fred > > > > Why?-- 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 https://groups.google.com/groups/opt_out.
Weston Platter
2012-Dec-08 18:51 UTC
Re: Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
I think I need to wrap class methods in a "module ClassMethods" block. require ''active_support/concern'' module M extend ActiveSupport::Concern included do scope :disabled, where(:disabled => true) end module ClassMethods ... endend On Sunday, December 2, 2012 7:06:31 PM UTC-6, Frederick Cheung wrote:> > > > On Dec 2, 9:00 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > On Dec 2, 7:22 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > What you said makes sense. > > > > > I incorrectly said I commented out > > > include MyEngine::SomeController > > > > > when I meant to say commenting out > > > extend ActiveSupport::Concern > > > > Calling extend activesupport::concern on a controller sounds like a > > weird thing to do > > - it''s supposed to be used on modules. What were you trying to do > > with it? > > And I assume that the reason this causes a problem is something to do > with how as::concern changes the behaviour of include so as to setup > module dependencies. > > Fred > > > > > > > > > > > > > > > > > > fixes the issue. > > > > > The codeabse is here, > https://github.com/twinge/questionnaire_engine/tree/8836c2a3b92e676ea... > > > . > > > > > The specific Controller Class is here, > https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ea... > > > > > The specific Controller Spec test is here, > https://github.com/twinge/questionnaire_engine/blob/8836c2a3b92e676ea... > > > > > On Saturday, December 1, 2012 7:11:02 PM UTC-6, Frederick Cheung > wrote: > > > > > > On Dec 1, 7:19 pm, Weston Platter <westonplat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > But, this breaks my rpsec controller tests because of an undefined > > > > > "recycle" method. > > > > > > > 12) Qe::Admin::QuestionPagesController POST reorder > > > > > Failure/Error: xhr :post, :create, > > > > > NoMethodError: > > > > > undefined method `recycle!'' for > > > > > #<Qe::Admin::QuestionPagesController:0x007f80aa1c7528> > > > > > # ./spec/controllers/admin/pages_controller_spec.rb:69:in > `block (2 > > > > > levels) in <top (required)>'' > > > > > > > When I comment out the "include MyEngine::Controller" everything > passes. > > > > > > If it''s commenting out the include that fixes things, why are you so > > > > sure that it''s the extend at fault rather than something else in the > > > > module? Personally I''d be inclined to thing that by including your > > > > module you''re accidentally shadowing an existing method on the > > > > controller - if you were to show a minimal example that reproduces > the > > > > problem rather than dummy code someone might be able to have a guess > > > > (I suspect the issue may have been lost in translation from your > > > > actual code to the example you gave since the latter isn''t valid > ruby > > > > (for example you''re including a class rather than a module) > > > > > > Fred > > > > > Why? >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xZq-sWuJtloJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-09 16:25 UTC
Re: Why does ''extend ActiveSupport::Concern'' cause `undefined method ''recycle!''`?
On Saturday, December 8, 2012 6:51:50 PM UTC, Weston Platter wrote:> > I think I need to wrap class methods in a "module ClassMethods" block. > > Yes, that''s the way to add class methods with AS::Concern.Fred> >> > > > > Why? >> >-- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/b4DmTgO7cXMJ. For more options, visit https://groups.google.com/groups/opt_out.