Thursday, 15 March 2012

Ruby On Rails - Using concerns in controllers -



Ruby On Rails - Using concerns in controllers -

possible noob warning: new ror

i trying utilize concerns in ror. right have simple concern writen

#./app/controllers/concerns/foo.rb module foo extend activesupport::concern def somethingfoo puts "ayyyy! foo" end end

when seek , utilize concern in controller undefined method error

#./app/controllers/foo_controller.rb class foocontroller < applicationcontroller include foo def show foo.somethingfoo # undefined method 'somethingfoo' foo:module render plain: "ohh no, doesnt show me because of error above me" end end

to knowledge somethingfoo should called not. have tried defining somethingfoo in included ... end block in concern not work either. there missing? can concerns not used controllers?

if include modules (extended activesupport::concern or not), methods of module become instance methods of including class/module.

your controller method should hence read

def show somethingfoo render plain: "yeah, i'm shown!" end

ruby-on-rails ruby web separation-of-concerns

No comments:

Post a Comment