APP_URL

3 views
Skip to first unread message

Barry Paul

unread,
Sep 11, 2008, 7:02:58 AM9/11/08
to CommunityEngine

A quick question. Is APP_URL really necessary? Seems like Rails
routing already knows the base URL of your application...

Thanks,

==
BP

Bryan Kearney

unread,
Sep 11, 2008, 8:20:45 AM9/11/08
to communi...@googlegroups.com
methinks this is mainly for the emails which are sent out.

-- bk

Valeri

unread,
Sep 12, 2008, 5:48:41 AM9/12/08
to CommunityEngine
APP_URL ?
It used in the:
1. base_helper.rb (def clippings_link)
2. index.rxml ( build xml: :startID=>"#{APP_URL}/#{@user.login_slug} )
3. email messages (ex.: <%= APP_URL %>/<%= @user.login_slug %>/
edit_account)

Barry Paul

unread,
Sep 12, 2008, 8:02:39 AM9/12/08
to communi...@googlegroups.com

I am not necessarily against global variables but my gut feeling was that there was something wrong/unnecessary with having one for the application URL. I had a look around the code and found that:

1. It is used in several different ways all of which are unnecessary (with the exception perhaps of email notifications)
2. It has led to some bad programming practices; it's used to break Rail's MVC pattern.

The worst case is where it is used in the models to write HTML and use named routes. This functionality belongs in the views and helpers.

For example in Photo.rb

 def link_for_rss
   "#{APP_URL}/#{self.user.login}/photos/#{self.to_param}"
 end

 def description_for_rss
   "<a href='#{self.link_for_rss}' title='#{self.name}'><img src='#{self.public_filename(:large)}' alt='#{self.name}' /><br />#{self.description}</a>"
 end

Or in many of the models URLWriter is included so that named routes can be used as follows.

 include ActionController::UrlWriter
 default_url_options[:host] = APP_URL.sub('http://', '')


To me, getting rid of the extra configuration step of setting APP_URL is not a necessity, but fixing the bigger problem of breaking the MVC pattern and thereby making the code easier to understand and maintain is worth doing.

I have been refactoring it in my copy of CE and when done will merge it into the source if people are interested.

Cheers,

--
BP

Bruno Bornsztein

unread,
Sep 12, 2008, 9:06:39 AM9/12/08
to communi...@googlegroups.com
Great! Sounds like a nice contribution, please let me know when it's ready to merge.
Thanks,
Bruno
Reply all
Reply to author
Forward
0 new messages