How can I possess act_as_taggable_on_stereoids using an account?

If I have a website logically divided into accounts (e.g. acme.mywebsite.com, xyz.mywebsite.com), how can I implement act-as-taggable-on-steroids and have tags occupied by the current account?

To get more detailed information, if I refer to acme, I do not want to see tags from the xyz subdomain.

I reviewed act-as-taggable-on, but context is only provided if you want to have different tag classes for the same model.

+4
source share
2 answers

Assuming I understand your question is that you have multiple accounts, each with its own set of tags, which can be applied to any application model that calls act_as_taggable. The following should do what you want.

You can add the following to the application controller to make the subdomain available for all actions.

class ApplicationController < ActionController::Base before_filter :getSubdomain def getSubdomain @current_subdomain.(self.request.subdomains[0]) end end 

Assuming you bind a tag to a subdomain in some way, like in your database, you can create a named scope. This example assumes that the subdomain is the username and your tag model belongs to the user, then you can use the named scope in your tag model to select only those that belong to the subobject.

 class Tag < ActiveRecord::Base ... named_scope :find_by_subdomain, labmda do |subdomain| { :joins => "users ON users.id = tags.user_id", :conditions => ["users.name = ?", subdomain] } end end 

Then, to retrieve tags in messages that were created by the user associated with the subdomain: Posts.tags.find_by_subdomain(@subdomain)

NB: you need to increase the tag model provided by act-as-taggable-on-steroids to add the following. - A column that associates each tag with an account. - Check the uniqueness for the scope. Allow multiple accounts with the same tags.

+3
source

If the account is a model for you, you can set up an object account with tags as the owner. Documentation: https://github.com/mbleigh/acts-as-taggable-on#tag-ownership

And then ask the Account to tag the object. Then, to find all the tags, you can ask the owner to get tags or tags.

+1
source

All Articles