RForum from sub-directory

How do I get RForum running from a sub-directory (/forum)? I thought I
could just change the Rewritebase to /forum but that doesn’t work.
Thanks in advance.

I wrote:

(1) Edit […]

Grrr. Sorry about the formatting. It seems the text area width is not
accurately representative of the hard-wrap width set within RForum.

Benjamin A. wrote:

How do I get RForum running from a sub-directory (/forum)? I thought I
could just change the Rewritebase to /forum but that doesn’t work.
Thanks in advance.

The changes you need to make are extensive, because RForum has a number
of places where it hard-codes URLs thereby igoring any sub-directory
that you specify.

The basics for any Rails application are onerous enough:

(1) Edit config/routes.rb and add the subdirectory to the paths in the
various map.connect lines - e.g.:

  map.connect '', :controller => 'forum', :action => 'list'

...becomes:

  map.connect '/forum', :controller => 'forum', :action => 'list'

You might want to do it using a variable instead (e.g. PATH_PREFIX) 

set
up in one of the environment files, in case you ever want to move
the
forum or make a copy of your installation on a different server
under a
different subdirectory.

  map.connect PATH_PREFIX + '', :controller => 'forum', :action => 

‘list’

(2) Tell the Helper URLs that you’re not running from root. You do this
by
hijacking the “asset host” stuff, so that images, scripts, CSS etc.
are
fetched from a different location. This only works for places where
a
helper method has been called to generate a URL, so all Rails apps
should
do this for all URLs, but many don’t and RForum is a good (bad?)
example.

Somewhere within the "Rails::initializer.run do |config|" block of
config/environment.rb, add:

  config.action_controller.asset_host = "/forum"

Now whether or not "/forum" works will depend on whether a path such 

as
“/forum/images/something.png” would work OK on your host. That will
in
turn depend on where the Rails application’s “public” folder lives.
So
modify the line above in order to generate correct links for
wherever
your Web server will go for items in the RForum “public” folder.

(3) If you run RForum out of a subdirectory the implication is that you
may
want to run multiple Rails applications on one host. If you do this,
the
name of the session cookies used by each will clash. To avoid this,
give
the cookie a unique name. In config/environment.rb or in one of the
files
in config/environments, add the following line outside the
“Rails::initializer.run do |config|” block:

  ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:session_key]
  = 'rforumapp_session_id'

You can use whatever name you want, it doesn't have to be
"rforumapp_session_id".

For many Rails applications, that’s enough. There may be the odd rogue
hard-coded URL to sort out. For RForum, there are loads of them. Check
the skin CSS files - CSS is a weakness for Rails, because you can’t use
ERB in CSS files so URLs to images and so-on must be hard-coded. If
you’re using a skin that references images you may, depending on where
you’ve put “public”, need to change the URLs in the CSS files.

You’re going to have to do some work with things making calls to any
method in the Mailer class (app/controllers/mailer.rb) because most
methods take a URL to include in a notification e-mail message. For some
reason in several places RForum callers construct URLs “by hand” using
@request.host and so-on. You need to change those into equivalent
“url_for” calls, e.g. in places like app/controllers/user_controller.rb
where it’s calling deliver_registration_mail.

You will similarly need to look in the various app/views fragments to
check for hard-coded URLs there; it’s been a while since I looked at
those since they were the first things I changed but ISTR similar issues
with URLs written into the RHTML where helper method calls should have
been. There were a couple of more tricky cases that I may have
temporarily just hard-coded to my own subdirectory in lieu of a proper
fix at a later time.

Incidentally, if you’re using PostgreSQL not MySQL you’ll find searches
don’t work because RForum uses a “LIMIT x,y” query form which PostgreSQL
doesn’t understand. In app/models/search_like.rb, change “LIMIT ?,?” to
“OFFSET ? LIMIT ?” to get what ought to be identical functionality
that’ll work in either database.

Doing all of this is a pain, which is why I’m offering to put these
fixes into the tree. For free, out of the goodness of my heart :slight_smile: -
except the authors haven’t responded to e-mail and nobody on this forum,
yet, has suggested where I should be going to submit such patches, and
all my IRC pleas to date have fallen on deaf ears. So I’ve a (almost
completely) relocatable version of RForum but nobody else can use it
right now. Doh. Can anyone help?

Benjamin,

I have the “patch” for the 2nd proposal by Andrew above. The following
is my attempt at fixing the code such that it doesn’t break
installations that (a) are at the host root; and (b) also works for
people like you and I that installed RForum under a host subdirectory:

{
hunk ./app/helpers/application_helper.rb 103

  • image_tag “/captcha/image?#{rand.to_s}”, :alt => “Captcha Image”
    hunk ./app/models/post.rb 68
  • Post.find(:all, :conditions => “deleted = 0”, ‘created_at DESC, id
    DESC’, :limit => number)
  • Post.find(:all, :conditions => [“deleted = 0”, ‘created_at DESC, id
    DESC’], :limit => number)
    hunk ./app/views/layouts/default.rhtml 8
  • <link type="text/css" rel="stylesheet" href="/stylesheets/main.css"

/>

  • <link type="text/css" rel="stylesheet" href="/stylesheets/syntax.css"

/>

  • <link type="text/css" rel="stylesheet" media="print"

href="/stylesheets/print.css" />

  • <%= stylesheet_link_tag ‘main’ -%>
  • <%= stylesheet_link_tag ‘syntax’ -%>
  • <%= stylesheet_link_tag ‘print’, :media => ‘print’ -%>
  • <%= javascript_include_tag ‘highlightCurrentLink’ -%>
  • <%= javascript_include_tag ‘findpos’ -%>
    hunk ./app/views/layouts/default.rhtml 14
  • <script src="/javascripts/highlightCurrentLink.js"

type=“text/javascript”>

  • <script src="/javascripts/findpos.js"

type=“text/javascript”>

  • $
    hunk ./app/views/layouts/default.rhtml 15
  • <link type="text/css" rel="stylesheet" media="screen"

href="/skins/<%= h @skin %>/style.css" />

  • <%= stylesheet_link_tag “/skins/#{@skin}/style”, :media => ‘screen’
    -%>
    }

Since this is an inclusive solution that doesn’t break one side or the
other, I suggest it gets submitted to the darcs RForum codebase - any
ideas how I should go about doing this?

Also if you haven’t already I suggest you add the following to the end
of your config/environment.rb added a similar fix (perhaps you are using
the horrible reverse_proxy plugin? The following is specific to those
wishing to run RForum from a subdirectory rather than the host root (and
in my opinion is cleaner than the reverse_proxy plugin code):
+module ActionController

  • protected
  • BASE_URL = “http://HOSTNAME/SUBDIR
  • ActionController::Base.asset_host = BASE_URL
  • class UrlRewriter
  •  alias old_rewrite_url rewrite_url
    
  •  # Prepends the BASE_URL to all of the URL requests created by the 
    

$

  •  # URL rewriter in Rails.
    
  •  def rewrite_url(path, options)
    
  •    url = old_rewrite_url(path, options)
    
  •    unless options[:skip_relative_url_root]
    
  •      url = url.gsub(@request.protocol + @request.host_with_port, 
    

‘’)

  •      url = BASE_URL + url
    
  •    end
    
  •    url
    
  •  end
    
  • end
    +end

Now I just have to figure out the problem I am having with RForum not
reading my site.rb preference for the skin and I should be all set…:slight_smile:

Hope this helps,
SP

Since this is an inclusive solution that doesn’t break one side or the
other, I suggest it gets submitted to the darcs RForum codebase - any
ideas how I should go about doing this?
To respond to myself, since I wasn’t sure about the protocol on this, I
sent the darcs patch over to Andreas via email (using darcs and
surprised how nice darcs is to use) and hoped this was the right (and
not too rude) way of doing this. Apologies if this is not the right
way. I would be happy to submit it another way.

Thanks,
SP

Hi,

I didn’t receive your patch. What address did you send it to?

Andreas

Andreas S. wrote:

I didn’t receive your patch. What address did you send it to?
For others following this thread, Andreas and I email each other off the
forum and about 10 days ago Andreas committing my patch to fix this
issue.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs