Rails app + caching and environment modes - ruby

I just finished setting up a Rackspace Cloud Server to host a website I'm going to build using Ruby on Rails. I've installed the latest versions of Apache, Rails, and Passenger (although to be honest, I'm not quite sure what Passenger gets me) - (I just checked, and Passenger doesn't come up in a gem list, but it is present in mods-enabled).
I've got everything set up, and I can get simple routes working with the appropriate controllers and views.
The problem I'm having is that it I can only see changes to a view after restarting Apache, so I assume some sort of caching is going on. I've followed several tips on SO for how to make sure I'm running in development mode, but nothing seems to work. I've placed a statement in my Apache config file, as well as in my Rails app's environment.rb file.
1) How can I see which mode I'm currently in?
2) How do I change it to whatever I need it to be?
Also, a lot of answers I'm finding are presuming that you're running your app in script/console mode. I'm working directly on the server via ssh, and I haven't ever had to turn my rails app on using script/console. It's just there and running.
Thanks
Update: If I print out Rails.env in a view, it lists production. If I fire up rails console on the command line, and print out Rails.env, it lists development.

Without seeing how you set the environment, this is the best advice I can give you.
<VirtualHost *>
ServerName example.com
DocumentRoot /home/yourname/htdocs/example.com/public
RailsEnv development
//Plus whatever else you might have in your standard Virtual Host
</VirtualHost>
After you edit this file you must restart Apache.

Related

What needs to be done when moving a ruby on rails (RoR) app to a different directory?

I generated the default RoR application with the rails new <project_name> command, and everything seemed to go fine. Later I decided I wanted to relocate my rails projects in a different directory (something other than my home directory), so I moved the RoR project to /opt/rails/<project_name> and I created a symlink in my web root pointing to /opt/rails/<project_name>/public, and the page loads fine, but some of the assets aren't loading on the Welcome aboard page, i.e. the rails.png And when I go to click on the About your application's environment link I get a 404 error. If I had to take a guess as to why I'm getting these errors it would have to be that I moved the rails app simple_cms from /home/user/www/rails/simple_cms to /opt/rails/simple_cms Is there a command I need to issue in the project root of simple_cms to get things fully working?
Update
I'm using Apache 2 as the web server on a CentOS 5.9 box.
If you are using rails s to launch your app, then there is no need to create symlinks. The web server (could be WEBrick, or Thin) will serve the application from the app root.
If you are using Apache or Nginx, again there is no need to create symlinks, but you need to let Apache/Nginx know the new location. For example, in a Nginx+Passenger setup, you would need to set passenger_app_root to the new location.
Provide more details in your question, or consult the documentation for your setup.

Using Phusion/mod_rails

I've been looking into using mod_rails (Phusion), but I just wanted to verify this: Once it's installed, I can still serve regular, non-rails apps from the same server without making any changes. Is this correct?
It is correct. I'm using Passenger in a project with other PHP projects and it works fine (even some PHP files in your public folder).
You can also set the passenger to start standalone (passenger start -d in your rails root folder) and use the mod_proxy and mod_rewrite from Apache to handle it (redirecting the rails requests to the rails app).
Yes, you can still serve non-rails applications using the same server.
mod_rails automatically detects which DocumentRoots are Rails applications by looking for public, for example.

Integrating Ruby on Windows WAMP server so I can run Ruby and PHP at same time?

I've been searching on this but haven't found anything decisive so far.. I already have a windows WAMP server up and running and am using it for my PHP apps, I want to be able to run some small ruby scripts (to interact with a library that is not available in PHP), I don't even need Rails at this point, I just want to run ruby scripts and be able to run them from within a web browser type environment (like PHP) but I can't figure out how to do this since the "instant rails" takes the same resources of php and apache so it can't run at the same time unless I change the port but I'd rather just make it so it runs off the same apache as my PHP apps ( I don't even need a database at this point as thats all handled in my php apps).. any advice is appreciated
Seeing that you have accepted the answer from your other question: you won't be able to run a ruby TCP server on port X and Apache on the same port.
On the other hand if you decide to use Rails: Install InstantRails but don't start it. Copy the portion of Apache config (in InstantRails directory) that binds rails to Apache and edit it to handle everything under (for eample) /rails then paste it into your Apache config that runs PHP. You may have to fiddle with paths (PATH variable). This way you'll have Apache running on port X, all *.php will go to your PHP interpreter and everything under (for example) /rails will go to Rails/Ruby

Is it possible to deploy a Ruby app on a plain clean Passenger setup?

I'm thinking to something really similar on what you can do with mod_php: drop an application in some way inside Apache and making it run with Passenger, without adding anything inside httpd.conf (no vhost, nothing except the basic Passenger configuration).
It's something very similar to Wordpress or many other frameworks: just unzip/svn checkout it inside a folder and run it.
I know that it's possible with CGI and FCGI, but I'm wondering if it's also possible to tap in the speed of Passenger.
I've tried fiddling with the Rack instructions on the official website trying to find a specific .htaccess and config.ru configuration, but nothing so far.
I know it's not common, but... is it even possible?
It's not possible without configuring a virtual host.
Rails applications are not like PHP files; files on the filesystem do not correspond with URLs. PHP files are placed within the DocumentRoot, whereas Rails/Rack apps live outside the DocumentRoot.
It is therefore not possible for Passenger to detect your application's location. You either need to tell it where it is located in the first place, or you need to point your virtual host's DocumentRoot to your application's /public directory. In that case Passenger will detect that it is a Rails/Rack app and you don't need additional Passenger configuration, but you do need a virtual host for each application.
Update: The Passenger docs mention that RailsBaseURI is allowed within a .htaccess file. Adding this in your document root and creating a symlink from a subdirectory (e.g. /docroot/yourapp) to the /public dir of your application might then be just what you need.
It all depends on what is already in your httpd.conf
You can't even run a PHP app without modifying your apache config files on many default apache installs.
Maybe dropping config.ru to some directory would do it?
It is almost possible. If the configuration is done right and apache+mod_rails knows where your application ist you need to change the last modified date of the /path/to/your/app/tmp/restart.txt. With ssh access you can do this like this
touch /path/to/your/app/tmp/restart.txt
more information can be found here: http://www.modrails.com/documentation/Users%20guide.html#_redeploying_restarting_the_ruby_on_rails_application
Update:
Or you can create the /path/to/your/app/tmp/always_restart.txt
more information about this can be found here:
http://www.modrails.com/documentation/Users%20guide.html#_making_the_application_restart_after_each_request

Running gem server in passenger

I'm running a few rails/rake apps in Apache/passenger and I want to add the documentation app served by gem server to these apps, so I can easily give it a special (sub)domain, like docs.example.org, so it's easily available for all members of our team and nobody has to start the server himself or remember port numbers (like 8808, the default gem server port).
I would recommend looking into bdoc instead of gem server, it allows the user to access all their gem docs without a server running at all. It would also be trivial to modify bdoc to output to a specific directory then you could easily add a step to regenerate the docs.
The nice thing about having them in static files would be the apache config is dead simple.
If you do want to make bdoc output to a specific dir look at this line.
Edit:
I actually went ahead and branched this on github and made the change. Now you can supply the output directory on the command line and it will generate the static rdoc pages for you.
I'm running http://gems.local on my machine in case I want to do some Ruby cracking offline. (Plain journey, trains, etc).
This is really easy, you can actually run passenger with all the Ruby gems' documentation locally without having to access the net.
I was following Jason's tips and got everything working. See the following article and you should be ready to go:
http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs
Attila
I wrote a blog post on how I have my gems, ruby, rails and jquery docs locally using the yard server and nginx for proxing in mac os x. Steps for linux are almost the same, only thing that changes is the way to configure the daemons.
https://makarius.posterous.com/offline-rails-ruby-jquery-and-gems-docs-with

Resources