Hey guys,

I think I might be a little confused but I cant really understand exactly
when to separate code into a concern, and when to separate it into a
library.

1. What's the exact difference?

2. Where are they available?

3. What is their goal? what is the goal of putting code in a concern and in
a library?

Hope i am not saying something completely dumb, but I couldn't really find
a comparison and I guess I am pretty new to the concept of concerns.


all the best,

Andre

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/af15f8d3-6e38-4470-9d24-401889fcfec4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Robert Walker at Jul 26, 2013 at 1:17 pm

    unknown wrote in post #1116591:
    I think I might be a little confused but I cant really understand
    exactly
    when to separate code into a concern, and when to separate it into a
    library.

    1. What's the exact difference?
    Concerns is a technique used to either share some behavior between
    models or to break down "chubby" models into smaller, more coherent
    pieces. Notice this is all about model objects.

    Library code on the other hand should be self contained, independent
    behaviors that can be use anywhere.
    2. Where are they available?
    Model Concerns: Any model object where you choose to include them.
    Notice that concerns "extend ActiveSupport::Concern" and therefore have
    that direct dependency.

    Controller Concerns: Similar to the model concerns except for
    controllers.

    Library: Should have no direct dependencies outside of itself (other
    than libraries a library directly depends upon. i.e Rails itself has
    many dependencies managed by RubyGems).

    You should (in theory) be able to include a library anywhere, even in
    apps that don't use Rails at all. Notice that many gems (libraries) are
    useful no matter what framework you use them with. You could have a
    Sinatra app and include the same gem as in a Rails app. There's no
    direct dependency there.
    3. What is their goal? what is the goal of putting code in a concern and
    in
    a library?
    This explains concerns pretty well I think:
    http://37signals.com/svn/posts/3372-put-chubby-models-on-a-diet-with-concerns

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1d3e3a59a45b3d60db7966150cdee30c%40ruby-forum.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • André Orvalho at Jul 27, 2013 at 10:27 am
    I have read the post. actually I have it read it several times to try to
    see if I could find the particular answer.

    But I guess I got my question answered. Independent is the key word here
    and that's what a library should be and the ability of using it anywhere. I
    think I just saw a lot of bad examples of how to use libraries. I was also
    getting confused since you can have concerns for models and controllers and
    that is almost everything in rails. But well I think I got a pretty good
    idea and will have to make design choices on my own for that case.

    But I still have the feeling that this can confuse much more people since
    it was introduced with one blog post and there is not big documentation
    about it on rails.(Concerns I mean)

    But hopefully we will get more information and new ways to use it!

    Thanks for your help,

    all the best,

    Andre

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAA6P50Y_c8i1_pD3vEvv11XzVHuBdfog%2BB%2BqyKjVsV0kWzQXaA%40mail.gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJul 24, '13 at 10:07p
activeJul 27, '13 at 10:27a
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

André Orvalho: 2 posts Robert Walker: 1 post

People

Translate

site design / logo © 2022 Grokbase