Questions tagged [activesupport-concern]
131 questions
46
votes
4 answers
How to test a Controller Concern in Rails 4
What is the best way to handle testing of concerns when used in Rails 4 controllers? Say I have a trivial concern Citations.
module Citations
extend ActiveSupport::Concern
def citations ; end
end
The expected behavior under test is that any…
![](../../users/profiles/224872.webp)
jelder
- 1,673
- 1
- 16
- 17
26
votes
3 answers
what is difference between using concerns vs modules in rails?
Just now I started to using Concerns in rails, but i have doubt why we go for concerns, because we can achieve same thing on module & mixing concept. So please any one tell about shat is the use of concerns instead of using module.
![](../../users/profiles/1926434.webp)
Ramkumar
- 303
- 1
- 3
- 6
25
votes
2 answers
Rails ActiveSuppport:Concern and Private Methods
This is a great idea about concern in rails: http://37signals.com/svn/posts/3372-put-chubby-models-on-a-diet-with-concerns
And it's also a good idea to make very small methods that are not part of a public API. Without using concerns, those become…
![](../../users/profiles/1009332.webp)
justingordon
- 11,553
- 9
- 64
- 111
15
votes
2 answers
How to create a Rails 4 Concern that takes an argument
I have an ActiveRecord class called User. I'm trying to create a concern called Restrictable which takes in some arguments like this:
class User < ActiveRecord::Base
include Restrictable # Would be nice to not need this line
restrictable except:…
![](../../users/profiles/20092.webp)
jesal
- 7,044
- 5
- 47
- 51
12
votes
1 answer
Rails concern method override another concern method doesn't work like normal modules
Let's say I have the following structure in ruby (no rails)
module Parent
def f
puts "in parent"
end
end
module Child
def f
super
puts "in child"
end
end
class A
include Parent
include…
user1011792
11
votes
1 answer
Rails 4 concerns: Give class instance variables to model
With Rails concerns I can give my model class methods and instance methods through modules by including them. No blog entry or thread that I've found mentions how I can include variables in my model though.
Specifically I would like to give my…
![](../../users/profiles/2443291.webp)
ZeroMax
- 239
- 3
- 12
10
votes
1 answer
Overriding methods in an ActiveSupport::Concern module which are defined by a class method in the same module
I have an ActiveSupport::Concern module which looks roughly like the following:
module MyModel
module Acceptance
extend ActiveSupport::Concern
included do
enum status: [:declined, :accepted]
end
def declined!
…
![](../../users/profiles/1603071.webp)
GMA
- 5,320
- 6
- 45
- 72
7
votes
1 answer
Exception: "load_missing_constant Circular dependency detected while autoloading constant" in Rails
I'm using Rails 4.0.2. I added sub directories (with model names) in Concern directory:
/app/models/concerns/company/cache_concern.rb
/app/models/concerns/user/cache_concern.rb
/app/models/concerns/document/cache_concern.rb
cache_concern.rb in…
![](../../users/profiles/1886295.webp)
Mahtin66
- 71
- 3
6
votes
0 answers
How to apply ActiveSupport::Concern to specific actions in my controller?
I'm using Grape to build an API.
I created an ActiveSupport::Concern let's say with the name Authentication and I applied some before filter so my concern looks like:
module Authentication
extend ActiveSupport::Concern
included do
before…
![](../../users/profiles/1080046.webp)
Eki Eqbal
- 4,681
- 6
- 38
- 74
6
votes
2 answers
Rails: TypeError: wrong argument type Class (expected Module)
Inside app/models/abc/xyz.rb
module Abc::Xyz
extend ActiveSupport::Concern
end
Inside app/models/abc.rb
class Abc < ActiveRecord::Base
include Abc::Xyz
end
When I try to fetch data from Abc.where(id: id) sometimes it works and sometimes it…
![](../../users/profiles/363503.webp)
krunal shah
- 15,347
- 24
- 90
- 136
5
votes
1 answer
how to include concerns module with only actions in rails controllers
Below is my concern Concerns::V1::PlanFinding for controllers. Depending on base controllers and actions, it calls set_plan
extend ActiveSupport::Concern
attr_accessor :plan, :custom_key
included do |base|
actions = case base.to_s
…
![](../../users/profiles/1938948.webp)
blankdeng
- 63
- 9
5
votes
1 answer
Rails 4.2 concern content ignored in test environment
I'm stuck in a really weird issue. I recently updated from rails 4.1 to 4.2. In 4.1 everything worked fine. But now, in 4.2, it seems model concern content is beig ignored, even if the concern is found.
Putting it simple. I have a Client model which…
![](../../users/profiles/877028.webp)
Waiting for Dev...
- 11,486
- 5
- 41
- 56
5
votes
1 answer
rails - problems with validation in concern
I have problems with validation in concern
There is class
/app/models/group.rb
class Group < AbstractModel
include Localized::Title
...
end
/app/models/concerns/localized/title.rb
module Localized::Title
extend ActiveSupport::Concern
…
![](../../users/profiles/1661323.webp)
greenif
- 927
- 1
- 8
- 22
4
votes
4 answers
How to use two concerns with the same name?
I want to use concerns app/controllers/concerns/likeable.rb and app/models/concerns/likeable.rb.
The first one goes to controllers and the second one goes to models.
If I create two files, only the first one is loaded.
What's the best way to…
![](../../users/profiles/1317162.webp)
blackst0ne
- 591
- 3
- 19
4
votes
1 answer
Accessing ActiveSupport::Concern class methods from within instance methods
I'm working my way through Michael Hartl's tutorial, but was finding the User class getting a bit cluttered. I wanted to clean it up a bit by pulling chunks of functionality into separate mixins (using the new-ish ActiveSupport::Concern, vs the…
![](../../users/profiles/3174443.webp)
TheWiseAxe
- 53
- 1
- 5