Hi all,

I am facing problem in getting subdomain name inside the model. The
following is my setup.

I am using cancan for authorization.I wanted a specific condition in
Ability.rb ( the file which is placed in models if we install cancan gem).

Below is the condition I wanted:
=========================================================
user ||= User.new # guest user (not logged in)
if (user.role == 'admin' && user.site_name == current_subdomain_name)
can :manage, :all
else
can :read, :all
end
=======================================================

current_subdomain_name should be the name of the subdomain on which user is
browsing. But i could not get it.

I have tried the following was but could not succeed.

1) setting a current_subdomain_name as a global variable in the application
controller and using the global variable. (using ruby debugger i found that
the global variable is having nil in it)
2) i have a method current_subdomain_name in the application helper which
returns what i wanted, I included the same inside the ability model and
tried to use the method . But was getting error .

3) writting a mehod in controller such that it returns what i wanted and
use the same in the model.Still could not succeed.


Can anybody let me know how to get the subdomain from request and use it in
the model (In Ability.rb which cancan provide).

Any help is highly appreciated.

Thanks,
Nror

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Siva Prasad at Nov 29, 2011 at 7:12 am
    Hi All,

    can somebody help me on this.

    --Siva
    On 11/28/2011 6:41 AM, newrails user wrote:
    Hi all,
    I am facing problem in getting subdomain name inside the model. The
    following is my setup.
    I am using cancan for authorization.I wanted a specific condition in
    Ability.rb ( the file which is placed in models if we install cancan gem).
    Below is the condition I wanted:
    =========================================================
    user ||= User.new # guest user (not logged in)
    if (user.role == 'admin' && user.site_name ==
    current_subdomain_name)
    can :manage, :all
    else
    can :read, :all
    end
    =======================================================
    current_subdomain_name should be the name of the subdomain on which
    user is browsing. But i could not get it.
    I have tried the following was but could not succeed.
    1) setting a current_subdomain_name as a global variable in the
    application controller and using the global variable. (using ruby
    debugger i found that the global variable is having nil in it)
    2) i have a method current_subdomain_name in the application helper
    which returns what i wanted, I included the same inside the ability
    model and tried to use the method . But was getting error .
    3) writting a mehod in controller such that it returns what i wanted
    and use the same in the model.Still could not succeed.
    Can anybody let me know how to get the subdomain from request and use
    it in the model (In Ability.rb which cancan provide).
    Any help is highly appreciated.
    Thanks,
    Nror
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Jim Ruther Nill at Nov 29, 2011 at 9:44 am

    On Mon, Nov 28, 2011 at 9:11 AM, newrails user wrote:

    Hi all,

    I am facing problem in getting subdomain name inside the model. The
    following is my setup.

    I am using cancan for authorization.I wanted a specific condition in
    Ability.rb ( the file which is placed in models if we install cancan gem).

    Below is the condition I wanted:
    =========================================================
    user ||= User.new # guest user (not logged in)
    if (user.role == 'admin' && user.site_name == current_subdomain_name)
    can :manage, :all
    else
    can :read, :all
    end
    =======================================================

    current_subdomain_name should be the name of the subdomain on which user
    is browsing. But i could not get it.

    I have tried the following was but could not succeed.

    1) setting a current_subdomain_name as a global variable in the
    application controller and using the global variable. (using ruby debugger
    i found that the global variable is having nil in it)
    2) i have a method current_subdomain_name in the application helper which
    returns what i wanted, I included the same inside the ability model and
    tried to use the method . But was getting error .

    3) writting a mehod in controller such that it returns what i wanted and
    use the same in the model.Still could not succeed.
    See if this works

    class Ability
    include CanCan::Ability

    def initialize(user, subdomain) #subdomain should now contain the current
    subdomain
    user ||= User.new
    ...
    end
    end

    Then in your application controller

    def current_ability
    @current_ability ||= Ability.new(current_user, current_subdomain_name)
    end

    class Ability
    include CanCan::Ability

    def initialize(user)
    user ||= User.new # guest user (not logged in)
    if user.admin?
    can :manage, :all
    else
    can :read, :all
    end
    endend



    Can anybody let me know how to get the subdomain from request and use it
    in the model (In Ability.rb which cancan provide).

    Any help is highly appreciated.

    Thanks,
    Nror




    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Peanut at Nov 30, 2011 at 7:38 am
    Hi
    have you tried the method request.subdomain
    Checkout the railscast on subdomains for more info
    http://railscasts.com/episodes/221-subdomains-in-rails-3

    Bye
    Rik
    On Nov 29, 10:44 am, Jim Ruther Nill wrote:
    On Mon, Nov 28, 2011 at 9:11 AM, newrails user wrote:








    Hi all,
    I am facing problem in getting subdomain name inside the model. The
    following is my setup.
    I am using cancan for authorization.I wanted a specific condition in
    Ability.rb ( the file which is placed in models if we install cancan gem).
    Below is the condition I wanted:
    =========================================================
    user ||= User.new # guest user (not logged in)
    if (user.role == 'admin' && user.site_name == current_subdomain_name)
    can :manage, :all
    else
    can :read, :all
    end
    =======================================================
    current_subdomain_name should be the name of the subdomain on which user
    is browsing. But i could not get it.
    I have tried the following was but could not succeed.
    1) setting a current_subdomain_name as a global variable in the
    application controller and using the global variable. (using ruby debugger
    i found that the global variable is having nil in it)
    2) i have a method current_subdomain_name in the application helper which
    returns what i wanted, I included the same inside the ability model and
    tried to use the method . But was getting error .
    3) writting a mehod in controller such that it returns what i wanted and
    use the same in the model.Still could not succeed.
    See if this works

    class Ability
    include CanCan::Ability

    def initialize(user, subdomain) #subdomain should now contain the current
    subdomain
    user ||= User.new
    ...
    end
    end

    Then in your application controller

    def current_ability
    @current_ability ||= Ability.new(current_user, current_subdomain_name)
    end

    class Ability
    include CanCan::Ability

    def initialize(user)
    user ||= User.new # guest user (not logged in)
    if user.admin?
    can :manage, :all
    else
    can :read, :all
    end
    endend










    Can anybody let me know how to get the subdomain from request and use it
    in the model (In Ability.rb which cancan provide).
    Any help is highly appreciated.
    Thanks,
    Nror
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    -------------------------------------------------------------
    visit my blog athttp://jimlabs.heroku.com
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Newrails user at Dec 4, 2011 at 1:57 am
    Jim

    Thanks it worked,

    --Nror
    On Tue, Nov 29, 2011 at 3:14 PM, Jim Ruther Nill wrote:


    On Mon, Nov 28, 2011 at 9:11 AM, newrails user wrote:

    Hi all,

    I am facing problem in getting subdomain name inside the model. The
    following is my setup.

    I am using cancan for authorization.I wanted a specific condition in
    Ability.rb ( the file which is placed in models if we install cancan gem).

    Below is the condition I wanted:
    =========================================================
    user ||= User.new # guest user (not logged in)
    if (user.role == 'admin' && user.site_name ==
    current_subdomain_name)
    can :manage, :all
    else
    can :read, :all
    end
    =======================================================

    current_subdomain_name should be the name of the subdomain on which user
    is browsing. But i could not get it.

    I have tried the following was but could not succeed.

    1) setting a current_subdomain_name as a global variable in the
    application controller and using the global variable. (using ruby debugger
    i found that the global variable is having nil in it)
    2) i have a method current_subdomain_name in the application helper which
    returns what i wanted, I included the same inside the ability model and
    tried to use the method . But was getting error .

    3) writting a mehod in controller such that it returns what i wanted and
    use the same in the model.Still could not succeed.
    See if this works

    class Ability
    include CanCan::Ability

    def initialize(user, subdomain) #subdomain should now contain the
    current subdomain
    user ||= User.new
    ...
    end
    end

    Then in your application controller

    def current_ability
    @current_ability ||= Ability.new(current_user, current_subdomain_name)
    end

    class Ability
    include CanCan::Ability

    def initialize(user)

    user ||= User.new # guest user (not logged in)

    if user.admin?

    can :manage, :all
    else
    can :read, :all
    end

    endend



    Can anybody let me know how to get the subdomain from request and use it
    in the model (In Ability.rb which cancan provide).

    Any help is highly appreciated.

    Thanks,
    Nror




    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 28, '11 at 1:12a
activeDec 4, '11 at 1:57a
posts5
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase