subdomain_fu

21 views
Skip to first unread message

Jarret Luft

unread,
Nov 11, 2009, 4:10:04 PM11/11/09
to Spree
I am attempting to configure subdomain_fu with spree, and have been
successful to the point that my routes are directing to the
appropriate controller. The gem appears to be installed and
configured properly, as the route directing works the way it is
expected to.

Where I get an error is anytime I try to call the subdomain_fu method
current_subdomain from within a spree controller, to read in the
current subdomain variable, rails gives me the error that the local
variable 'current_subdomain' does not exist in the current scope.

I have not worked with subdomain_fu before, and am wondering if anyone
has experience with this error (a google search turns up very little),
or if something about the structure of spree would alter the scope and
make the current_subdomain method call not work as expected.

I am using spree 0.9.2 in development mode on my local machine, and
have configured my /etc/hosts for the specific subdomains I am
testing.

Any thoughts around this would be appreciated.

Regards,
-Jarret.

Brian Quinn

unread,
Nov 12, 2009, 4:05:54 AM11/12/09
to spree...@googlegroups.com
Hi Jarret,

You might try adding something like this into the environment.rb

# Include your application configuration below
# These are the sizes of the domain (i.e. 0 for localhost, 1 for something.com)
# for each of your environments
SubdomainFu.tld_sizes = { :development => 1,
                          :test => 0,
                          :production => 1 }

# These are the subdomains that will be equivalent to no subdomain
SubdomainFu.mirrors = ["www"]

# This is the "preferred mirror" if you would rather show this subdomain
# in the URL than no subdomain at all.
SubdomainFu.preferred_mirror = "www"


Regards,

BDQ

Jarret Luft

unread,
Nov 12, 2009, 11:25:20 AM11/12/09
to spree...@googlegroups.com
Hi Brian,
Thanks for the reply.

My /etc/hosts is set up to point 127.0.0.1 to mysite.local (the tld), some_sub1.mysite.local, some_sub2.mysite.local, etc...
I have configured the tld_sizes parameter as 1 in dev, test and prod.

Unfortunately, because I can't access the current_subdomain from within a controller, I can't tell what it is actually returning as the subdomain piece of the url, vs the tld piece. 
I can only say that it is redirecting properly because when i provide http://mysite.local:3000 as the url, i am redirected to spree's default root (:products/:index), and when i try http://some_sub1.mysite.local:3000 i am taken to my subdomain controller where rails then produces an error because I have a before_filter trying to read the current_subdomain method which it says is undefined.

So it would seem that from the current scope within my subdomain controller, where I was hoping to take certain actions based on the subdomain specified, the subdomain_fu method 'current_subdomain' is not accessable...

Any other thoughts?
Thanks again,
-J.

Jarret Luft

unread,
Nov 12, 2009, 9:16:26 PM11/12/09
to Spree
It appears I have corrected this issue, but am still not sure why it
happened.

I uninstalled the subdomain_fu gem and removed the config.gem
initializer line, and opted to try the plugin instead. With the
plugin installed and no other configuration changes, I can now call
current_subdomain and current_domain as expected.

Regards,
-J.

On Nov 12, 9:25 am, Jarret Luft <jarret.l...@gmail.com> wrote:
> Hi Brian,
> Thanks for the reply.
>
> My /etc/hosts is set up to point 127.0.0.1 to mysite.local (the tld),
> some_sub1.mysite.local, some_sub2.mysite.local, etc...
> I have configured the tld_sizes parameter as 1 in dev, test and prod.
>
> Unfortunately, because I can't access the current_subdomain from within a
> controller, I can't tell what it is actually returning as the subdomain
> piece of the url, vs the tld piece.
> I can only say that it is redirecting properly because when i providehttp://mysite.local:3000as the url, i am redirected to spree's default root
> (:products/:index), and when i tryhttp://some_sub1.mysite.local:3000i am
> taken to my subdomain controller where rails then produces an error because
> I have a before_filter trying to read the current_subdomain method which it
> says is undefined.
>
> So it would seem that from the current scope within my subdomain controller,
> where I was hoping to take certain actions based on the subdomain specified,
> the subdomain_fu method 'current_subdomain' is not accessable...
>
> Any other thoughts?
> Thanks again,
> -J.
>
> On Thu, Nov 12, 2009 at 2:05 AM, Brian Quinn <briandqu...@gmail.com> wrote:
> > Hi Jarret,
>
> > You might try adding something like this into the environment.rb
>
> > # Include your application configuration below
> > # These are the sizes of the domain (i.e. 0 for localhost, 1 for
> > something.com)
> > # for each of your environments
> > SubdomainFu.tld_sizes = { :development => 1,
> >                           :test => 0,
> >                           :production => 1 }
>
> > # These are the subdomains that will be equivalent to no subdomain
> > SubdomainFu.mirrors = ["www"]
>
> > # This is the "preferred mirror" if you would rather show this subdomain
> > # in the URL than no subdomain at all.
> > SubdomainFu.preferred_mirror = "www"
>
> > Regards,
>
> > BDQ
>

Brian Quinn

unread,
Nov 13, 2009, 3:23:47 AM11/13/09
to spree...@googlegroups.com
That's an interesting one, if you add back in config.gem does it stop working again?

Jarret Luft

unread,
Nov 13, 2009, 9:56:37 AM11/13/09
to spree...@googlegroups.com
Hi Brian, you may have just pointed me to my initial mistake:

Initially, I had been placing the config.gem line into the my_extension.rb file for my extension as follows:

def self.require_gems(config)
    config.gem 'mbleigh-subdomain-fu', :source => "http://gems.github.com", :lib => "subdomain-fu"
end

Upon your suggestion, I added this line back in, and the site continued to function properly.
Then I removed the subdomain plugin folder from vendors/plugins to see if it would fail again, and it did fail.

Then I tried adding the config.gem line directly to the spree environment.rb file, and it works fine again now, using the gem instead of the plugin.

Is there something wrong with my code above, that would have caused the gem not to work properly when initialized from within my_extension.rb?

I will leave it in environment.rb for now, but as this applies only to my extension, I would prefer to have it in my extension code, and not in the base code...

-Jarret.

outinfive

unread,
Nov 13, 2009, 12:02:32 PM11/13/09
to Spree
hi,

I am also using 0.9.2 gem install.
I have just recreated similar behavior with the formtastic gem. I
have added it as a gem in my extension file but it is not available in
my views as expected. Adding the config.gem line to the {RAILS_ROOT}/
config/environment.rb allows the formtastic gem to work. Must be
something in how the gem is built.

I have been able to use RedCloth gem in an extension so I know I can
add a gem to an extension file and get it to work.

--
Matt


On Nov 13, 8:56 am, Jarret Luft <jarret.l...@gmail.com> wrote:
> Hi Brian, you may have just pointed me to my initial mistake:
>
> Initially, I had been placing the config.gem line into the my_extension.rb
> file for my extension as follows:
>
> def self.require_gems(config)
>     config.gem 'mbleigh-subdomain-fu', :source => "http://gems.github.com",
> :lib => "subdomain-fu"
> end
>
> Upon your suggestion, I added this line back in, and the site continued to
> function properly.
> Then I removed the subdomain plugin folder from vendors/plugins to see if it
> would fail again, and it did fail.
>
> Then I tried adding the config.gem line directly to the spree environment.rb
> file, and it works fine again now, using the gem instead of the plugin.
>
> Is there something wrong with my code above, that would have caused the gem
> not to work properly when initialized from within my_extension.rb?
>
> I will leave it in environment.rb for now, but as this applies only to my
> extension, I would prefer to have it in my extension code, and not in the
> base code...
>
> -Jarret.
>
>
>
> On Fri, Nov 13, 2009 at 1:23 AM, Brian Quinn <briandqu...@gmail.com> wrote:
> > That's an interesting one, if you add back in config.gem does it stop
> > working again?
>
> > On Fri, Nov 13, 2009 at 2:16 AM, Jarret Luft <jarret.l...@gmail.com>wrote:
>
> >> It appears I have corrected this issue, but am still not sure why it
> >> happened.
>
> >> I uninstalled the subdomain_fu gem and removed the config.gem
> >> initializer line, and opted to try the plugin instead.  With the
> >> plugin installed and no other configuration changes, I can now call
> >> current_subdomain and current_domain as expected.
>
> >> Regards,
> >> -J.
>
> >> On Nov 12, 9:25 am, Jarret Luft <jarret.l...@gmail.com> wrote:
> >> > Hi Brian,
> >> > Thanks for the reply.
>
> >> > My /etc/hosts is set up to point 127.0.0.1 to mysite.local (the tld),
> >> > some_sub1.mysite.local, some_sub2.mysite.local, etc...
> >> > I have configured the tld_sizes parameter as 1 in dev, test and prod.
>
> >> > Unfortunately, because I can't access the current_subdomain from within
> >> a
> >> > controller, I can't tell what it is actually returning as the subdomain
> >> > piece of the url, vs the tld piece.
> >> > I can only say that it is redirecting properly because when i
> >> providehttp://mysite.local:3000asthe url, i am redirected to spree's

outinfive

unread,
Nov 13, 2009, 12:08:50 PM11/13/09
to Spree
HAHA! As soon as I finished sending the last post I checked
something. Both subdomain_fu and formastic add to Base, one on
Actioncontroller and the other on ActionView.

ActionController::Base.send :include, SubdomainFu::Controller

ActionView::Base.send :include, Formtastic::SemanticFormHelper

I added the line to my extension file in the activate method. Things
appear to work now.
> > >> providehttp://mysite.local:3000astheurl, i am redirected to spree's

Jarret Luft

unread,
Nov 13, 2009, 7:49:10 PM11/13/09
to spree...@googlegroups.com
Thanks for the info Matt,

I was able to get it working with a slight modification of your suggestion.
I added the following into my extension's activate method:

require 'subdomain-fu'

ActionController::Base.send :include, SubdomainFu::Controller

Now it works with all of my configuration in the extension.
-J.

konsty

unread,
Dec 29, 2009, 5:31:25 AM12/29/09
to Spree
Hi guys,
I had the same issues with formtastic and adding a line to activate
method as Matt proposed have fixed things.

But for me another approach worked as well. I have my gems freezed in
vendor/gems folder. And this problem wilth formtastic goes away if I
do
rake gems:unpack:dependencies

hope this helps,
Kostya

On Nov 14, 8:49 am, Jarret Luft <jarret.l...@gmail.com> wrote:
> Thanks for the info Matt,
>
> I was able to get it working with a slight modification of your suggestion.
> I added the following into my extension's activate method:
>
> require 'subdomain-fu'
> ActionController::Base.send :include, SubdomainFu::Controller
>
> Now it works with all of my configuration in the extension.
> -J.
>

konsty

unread,
Dec 31, 2009, 2:15:05 AM12/31/09
to Spree
Uuups.
I was wrong.
Please ignore my last message.
Reply all
Reply to author
Forward
0 new messages