Hello,
I''m trying to build an app (mysuperapp.com) that allows users to
create an account in which a default subdomain (IE:
joeshmoe.mysuperapp.com) will be
created as their homepage. In their profile settings, I also want to
give them the ability to add their own domain name so their homepage now
can be joeshmoe.com. I know this is possible in rails w/ plugins like
subdomainfu and w/out plugins in rails3. I''ve searched countless
websites on the subject and I''m attempting to build an app based on
this
example:
http://glac-ialis.postmodo.com/ (take out the hypen if you want to go
to this link - caused a spam alert)
so, as in this example, I''ve created lib/personalized_domain.rb
[code]
# lib/personalized_domain.rb
class PersonalizedDomain
def self.matches?(request)
case request.host
when ''www.#{APP_CONFIG[:domain]}'',
''#{APP_CONFIG[:domain]}'', nil
false
else
true
end
end
end
[/code]
and in my routes I have this:
[code]
# config/routes
constraints(PersonalizedDomain) do
namespace :personalized, :path => ''/'' do
root :to => "projects#show"
resource :project
end
end
root :to => "home#index"
[/code]
in my model I have:
[code]
# app/models/project.rb
before_validation :cache_domain
validates_uniqueness_of :subdomain,
:cached_domain
validates_uniqueness_of :cname_alias,
:allow_blank => true
validates_presence_of :subdomain,
:cached_domain
validates_exclusion_of :subdomain,
:in => %w(admin blog),
:message => "is taken"
def cache_domain
self.cached_domain = if self.cname_alias.blank?
"#{self.subdomain}.#{APP_CONFIG[:domain]}"
else
"#{self.cname_alias}"
end
end
[/code]
as per the example, my base controller:
[code]
# app/controllers/personalized/base_controller.rb
class Personalized::BaseController < ApplicationController
before_filter :get_project
protected
def get_project
@project = Project.first(:conditions => {
:cached_domain => request.host
})
end
end
[/code]
One thing I noticed, in PersonalizedDomain, was that if I put a debug
statement in the self.matches? method as such:
[code]
class PersonalizedDomain
def self.matches?(request)
Rails.logger.info("****(PersonalizedDomain::self.matches?)-->>APP_CONFIG[:domain]:
#{APP_CONFIG[:domain]}")
case request.host
when ''www.#{APP_CONFIG[:domain]}'',
''#{APP_CONFIG[:domain]}'', nil
false
else
true
end
end
end
[/code]
the debug statement never get''s executed.
Thanks for any help
--
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
clem_c_rock
2011-Apr-22 05:25 UTC
Rails 3 Foreign Domain routing - cannot get this to work!
Hello,
I''m trying to build an app (mysuperapp.com) that allows users to
create
an account in which a default subdomain (IE: joeshmoe.mysuperapp.com) will
be
created as their homepage. In their profile settings, I also want to give
them the ability to add their own domain name so their homepage now can be
joeshmoe.com. I know this is possible in rails w/ plugins like
subdomainfu and w/out plugins in rails3. I''ve searched countless
websites
on the subject and I''m attempting to build an app based on this
example:
http://glacialis.postmodo.com/
so, as in this example, I''ve created lib/personalized_domain.rb
[code]
# lib/personalized_domain.rb
class PersonalizedDomain
def self.matches?(request)
case request.host
when ''www.#{APP_CONFIG[:domain]}'',
''#{APP_CONFIG[:domain]}'', nil
false
else
true
end
end
end
[/code]
and in my routes I have this:
[code]
# config/routes
constraints(PersonalizedDomain) do
namespace :personalized, :path => ''/'' do
root :to => "projects#show"
resource :project
end
end
root :to => "home#index"
[/code]
in my model I have:
[code]
# app/models/project.rb
before_validation :cache_domain
validates_uniqueness_of :subdomain,
:cached_domain
validates_uniqueness_of :cname_alias,
:allow_blank => true
validates_presence_of :subdomain,
:cached_domain
validates_exclusion_of :subdomain,
:in => %w(admin blog),
:message => "is taken"
def cache_domain
self.cached_domain = if self.cname_alias.blank?
"#{self.subdomain}.#{APP_CONFIG[:domain]}"
else
"#{self.cname_alias}"
end
end
[/code]
as per the example, my base controller:
[code]
# app/controllers/personalized/base_controller.rb
class Personalized::BaseController < ApplicationController
before_filter :get_project
protected
def get_project
@project = Project.first(:conditions => {
:cached_domain => request.host
})
end
end
[/code]
One thing I noticed, in PersonalizedDomain, was that if I put a debug
statement in the self.matches? method as such:
[code]
class PersonalizedDomain
def self.matches?(request)
Rails.logger.info("****(PersonalizedDomain::self.matches?)-->>APP_CONFIG[:domain]:
#{APP_CONFIG[:domain]}")
case request.host
when ''www.#{APP_CONFIG[:domain]}'',
''#{APP_CONFIG[:domain]}'', nil
false
else
true
end
end
end
[/code]
the debug statement never get''s executed.
Thanks for any help
--
View this message in context:
http://old.nabble.com/Rails-3-Foreign-Domain-routing---cannot-get-this-to-work%21-tp31454390p31454390.html
Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
clem_c_rock
2011-Apr-29 14:48 UTC
Re: Rails 3 Foreign Domain routing - cannot get this to work!
Here''s an update - I did figure out why my custom constraint
wasn''t working
correctly and here''s the changes I made:
In PersonalizedDomain I changed the self.matches? method from a class method
to an instance method as such:
[code]
# lib/personalized_domain.rb
class PersonalizedDomain
def matches?(request)
case request.host
when "www.#{APP_CONFIG[:domain]}",
"#{APP_CONFIG[:domain]}", nil
false
else
true
end
end
end
[/code]
and in routes I did this:
[code]
constraints(PersonalizedDomain.new) do
resources :posts
resources :personalized
end
[/code]
clem_c_rock wrote:>
>
> Hello,
> I''m trying to build an app (mysuperapp.com) that allows users
to
> create an account in which a default subdomain (IE:
> joeshmoe.mysuperapp.com) will be
> created as their homepage. In their profile settings, I also want to
> give them the ability to add their own domain name so their homepage now
> can be joeshmoe.com. I know this is possible in rails w/ plugins like
> subdomainfu and w/out plugins in rails3. I''ve searched countless
> websites on the subject and I''m attempting to build an app based
on this
> example:
>
> http://glacialis.postmodo.com/
>
> so, as in this example, I''ve created lib/personalized_domain.rb
>
> [code]
> # lib/personalized_domain.rb
> class PersonalizedDomain
> def self.matches?(request)
> case request.host
> when ''www.#{APP_CONFIG[:domain]}'',
''#{APP_CONFIG[:domain]}'', nil
> false
> else
> true
> end
> end
> end
> [/code]
>
>
> and in my routes I have this:
>
> [code]
> # config/routes
> constraints(PersonalizedDomain) do
> namespace :personalized, :path => ''/'' do
> root :to => "projects#show"
> resource :project
> end
> end
>
>
> root :to => "home#index"
> [/code]
>
>
> in my model I have:
>
> [code]
> # app/models/project.rb
> before_validation :cache_domain
>
> validates_uniqueness_of :subdomain,
> :cached_domain
> validates_uniqueness_of :cname_alias,
> :allow_blank => true
> validates_presence_of :subdomain,
> :cached_domain
> validates_exclusion_of :subdomain,
> :in => %w(admin blog),
> :message => "is taken"
>
> def cache_domain
> self.cached_domain = if self.cname_alias.blank?
> "#{self.subdomain}.#{APP_CONFIG[:domain]}"
> else
> "#{self.cname_alias}"
> end
> end
> [/code]
>
>
> as per the example, my base controller:
> [code]
> # app/controllers/personalized/base_controller.rb
> class Personalized::BaseController < ApplicationController
> before_filter :get_project
>
> protected
> def get_project
> @project = Project.first(:conditions => {
> :cached_domain => request.host
> })
> end
> end
> [/code]
>
>
> One thing I noticed, in PersonalizedDomain, was that if I put a debug
> statement in the self.matches? method as such:
>
> [code]
> class PersonalizedDomain
> def self.matches?(request)
>
>
Rails.logger.info("****(PersonalizedDomain::self.matches?)-->>APP_CONFIG[:domain]:
> #{APP_CONFIG[:domain]}")
> case request.host
> when ''www.#{APP_CONFIG[:domain]}'',
''#{APP_CONFIG[:domain]}'', nil
> false
> else
> true
> end
> end
> end
> [/code]
>
> the debug statement never get''s executed.
>
> Thanks for any help
>
--
View this message in context:
http://old.nabble.com/Rails-3-Foreign-Domain-routing---cannot-get-this-to-work%21-tp31454390p31506127.html
Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.