Stupid newbie question

Yes, Im new to Ruby. COming from PHP/Java world. I DON'T want to learn ruby, sigh. Anyway I got a project that is done in ruby and it need some modifications sometimes.

So until now, dont know how, I managed fixing a few things on that application. Sometimes was about setting a page to show more fields than before. Or maybe block a page redirecting it to an access denied page.

But now things are gotting more serious and bigger modifications are needed. I think I can manage doing that. But working like have done until now is VERY unefficient. Basically, Im working directly on a test server. I NEVER managed (this is the real big problem) in installing the app, correctly, on my local machine. Im getting mad in trying to do it it but with no success.

Thus the problem is about succesing in making the local app working. Explaining in details everything I guess would make most of you stop reading this post. So I try with another strategy. Here it comes:

I am on MAC. Ruby is installed by default. I MUST use Apache as server. So I put a virtual host poiting to /MY_PATH_RO_ROR_APP/public

When typing http://localhost/ then I see the content of the public folder.

The APP is "empty". Im not using things like generate or scaffolding. Why? Well, because my thought was to just copy all the application located on the test-server and making it work. Is that bad? I dont know. I would prefer not to go through all ruby stuff. If it is bad it is ok, as long as this is not the cause of the thing that the app is not working.

What I need to do is to create a controller manually and connect it through the route.rb.

i create a file in the app folder named product_controller.rb:

class ProductController < ApplicationController

  def show   render :text => 'abcd'   return   end

end

Now I want to map the route. How can I do this? I tried different ways. For example:

map.resources :product

or map.connect ':controller/:action/:id'

or map.connect ':controller/:action/:id.:format'

or map.connect ':product/:show'

Well, everytime I try then to type something in the browser. I try for example:

localhost/product/1 localhost/product/show localhost/product/1/show localhost/product

Well, all the time I can see the same error in the log:

File doesnt exist.

Right now Im thinking that the url-requests are managed by apache. And that apache doesnt understand that this is a ROR app? Is that the problem maybe??? And does anyone know how to make apache understand that that one is a ruby app??

Out of the box apache doesn't understand rails apps. You need to install passenger (sudo gem install passenger) which includes an apache module for handling rails app. The passenger site has loads of documentation.

Fred

Yes, that’s the problem.

Unlike PHP, your Rails app needs to run as a server listening on a port. You can’t just point Apache to your Rails directory. You can use any number of servers to accomplish this (WEBrick, thin, passenger).

The simplest way to start your rails application is by running “rails server” from within your rails application directory.

I think the current preferred setup for production environments is using Phusion Passenger, which can run as an Apache module. Check out the documentation here:

http://www.modrails.com/documentation.html

Yes, Im new to Ruby. COming from PHP/Java world. I DON'T want to learn ruby, sigh.

Welcome...

I am on MAC. Ruby is installed by default. I MUST use Apache as server. So I put a virtual host poiting to /MY_PATH_RO_ROR_APP/public

Yeah... that's not how it's done. What have you looked at for configuring Apache with Rails? You'll need Passenger or something similar to manage the Rails app - you're just showing the HTML at the moment, and nothing is processing the Ruby code.

my thought was to just copy all the application located on the test-server and making it work. Is that bad? I dont know.

If you have an existing app, this is fine.

i create a file in the app folder named product_controller.rb:

class ProductController < ApplicationController

map.resources :product

Typically, this should be "products_controller" and ProductsController, and your route should work (once Passenger is serving...)

Yes, Im new to Ruby. COming from PHP/Java world. I DON'T want to learn ruby, sigh. Anyway I got a project that is done in ruby and it need some modifications sometimes.

So until now, dont know how, I managed fixing a few things on that application. Sometimes was about setting a page to show more fields than before. Or maybe block a page redirecting it to an access denied page.

But now things are gotting more serious and bigger modifications are needed. I think I can manage doing that. But working like have done until now is VERY unefficient. Basically, Im working directly on a test server. I NEVER managed (this is the real big problem) in installing the app, correctly, on my local machine. Im getting mad in trying to do it it but with no success.

Thus the problem is about succesing in making the local app working. Explaining in details everything I guess would make most of you stop reading this post. So I try with another strategy. Here it comes:

I am on MAC. Ruby is installed by default. I MUST use Apache as server. So I put a virtual host poiting to /MY_PATH_RO_ROR_APP/public

When typing http://localhost/ then I see the content of the public folder.

The APP is "empty". Im not using things like generate or scaffolding. Why? Well, because my thought was to just copy all the application located on the test-server and making it work. Is that bad? I dont know. I would prefer not to go through all ruby stuff. If it is bad it is ok, as long as this is not the cause of the thing that the app is not working.

What I need to do is to create a controller manually and connect it through the route.rb.

i create a file in the app folder named product_controller.rb:

class ProductController < ApplicationController

def show    render :text => 'abcd'    return end

end

Now I want to map the route. How can I do this? I tried different ways. For example:

map.resources :product

or map.connect ':controller/:action/:id'

or map.connect ':controller/:action/:id.:format'

or map.connect ':product/:show'

Well, everytime I try then to type something in the browser. I try for example:

localhost/product/1 localhost/product/show localhost/product/1/show localhost/product

Well, all the time I can see the same error in the log:

File doesnt exist.

Right now Im thinking that the url-requests are managed by apache. And that apache doesnt understand that this is a ROR app? Is that the problem maybe??? And does anyone know how to make apache understand that that one is a ruby app??

Apache alone can't serve a Rails app. You need passenger.

Rails also comes with a webserver if u cd to the project dir and type script/server

If you need to maintain a rails app it might be good to learn some Ruby. Trust me there are worst things out there. Google tryruby

Above I made the guess that ur app is not rails 3. You should find what version of rails you are using because something like routing differs.

-Noel

Ok guys. Thank you all. I have been fighting with this for several days. And only while I was writing the first post I realized that, well, Apache need to know that one is a ror app sigh! SO most of you reccomend passenger. I hade a look at the doc. The I thought it would be better to just go straight forward and install it. I tried on two diffferent mac os x. First on tiger and then on leopard. In both case the same problem. Both say ERROR: Error installing passenger: ERROR: Failed to build gem native extension.

Well, Im so tired of all this, so I want wait before trying to understand whats going on. I only want one thing. Only one. I wanna see that damned upp running on my local machine. So, what about running the ruby server? Fine. So I run the command gem server Going to localhost:8808 I can see the list of all installed gems. But of course I want to see my app. How can I see that? OPN the test server it is enough to just type:

serverurl/portals/1

Well, I only get a 404 error.

The I was thinking: why should gem server know where the app is? I mean, where is the root of the server when you run gem server? Does it depend on where, in what location, it is run? I tried to run it into the folder containing my app, but without success. SO the question is (I guess): where is the root folder for all the ruby apps?

SO most of you reccomend passenger.

In both case the same problem. Both say ERROR: Error installing passenger: ERROR: Failed to build gem native extension.

Probably trivial to fix -- do you have all the XCode developer stuff on your system(s)? In any case...

Well, Im so tired of all this, so I want wait before trying to understand whats going on. I only want one thing. Only one. I wanna see that damned upp running on my local machine. So, what about running the ruby server? Fine. So I run the command gem server

`gem server` is strictly for viewing gem documentation, not running apps.

Assuming a Rails 2.x app, running `script/server` in the root of your application will start the built-in Webrick server.

HTH,

Well, I guess it was not so trivial. In short: I have been trying to run either through passenger or webrick. Passengers fails. I can install it, after installing macports. But when I have to run the command for installing under apache then it fails. I have tried to find answers but with no success.

So now Im trying to make it run under webrick. I succeded in installing a new ruby, thanks to macports. Now when I run ruby -version I get1.8.7

Anyway, when I trie to start the webrick server with the command: script/rails server

Then I get the following error:

APP_PATH/config/boot.rb:1:in `require': no such file to load -- rubygems (LoadError)

The file boot.rb contains the line

require 'rubygems'

It seems like an enviroment issue. I have searched for this, but could not find a solution that fit my situation. Looks like the enviroment dont really know where to look, or it looks in the wrong place, for the required rubygems.

Any hints folk?

RVM to the rescue I guess: Go here: https://rvm.beginrescueend.com/

install it, then go to http://rubygems.org/ and install rubygems (might actually be installed with rvm, you need to check this).

Isnt there an easier way? I have been installing undreded of software the latest day. I guess it is a problem in knowing which ruby runs when I put the command for starting the server. Im afraid that the old ruby is the one thats selected when I try to run the webrick server.

It is ONE line copy and pasted into your shell and really the recommended way to use Ruby on the Mac. It does not get much simpler than this.

Passengers fails. I can install it, after installing macports. But when I have to run the command for installing under apache then it fails. I have tried to find answers but with no success.

Well, you certainly won't get any answers without providing the exact error message - "it fails" is not useful.

So now Im trying to make it run under webrick. I succeded in installing a new ruby, thanks to macports. Now when I run ruby -version I get1.8.7

Anyway, when I trie to start the webrick server with the command: script/rails server

You seem to be mixing up commands between Rails 2.x and 3.x. Which do you have installed? Or more to the point, what is the app you're trying to run based on?

Ok IN that case I will give it a try. Thanks.

Well If I type rails -v (I guess this is the right way?) then I see Rails 1.2.6

I believe you're doomed :slight_smile:

Seriously, this has massive pain written all over it; 1.2.6 is ancient.

If I were you, I'd find someone who knows Rails, let her/him log into the test server you previously mentioned and clone the environment there (and the app + database + etc.) into a Linux VM. Then install that VM on your Mac and enjoy.

I suspect such a person could also offer some general tips to make your Rails work more productive and enjoyable.

Good luck!

Oh My God....

Well I tried to do like Martin suggested, installing RVM. Non error message when doing it. But When trying to install gems then I get the error: You need version >= 1.8.7

The funny thing is that I installed that version with macports. But for some reason it doesnt become the selected one (even thought running ruby -v show the version 1.8.7 sigh).

Now I thought I maybe can try getting the latest rails? No success. ERROR: Error installing rails:   activesupport requires Ruby version >= 1.8.7.

Its basically the same problem. The bash doesnt understand that there is a newer ruby. Maybe its about going deeper and set the appropriate path? Dont really know where to begin, sigh.

Btw, the current, preferred way of getting pretty much all formulas is Homebrew. Clean, easy, simple. Also, I was gonna upvote the RVM recommendation until I realized…yeah…

try:

  1. install RVM and don’t use 1.8.7. Use 1.8.6.

  2. make sure your RubyGems is working

cd /path/to/rails/app/dir

ruby script/server OR rails script/server

Oh, also, here’s a trip down memory lane: Ruby on Rails — Rails 1.2: REST admiration, HTTP lovefest, and UTF-8 celebrations

After using RVM with ruby 1.8.6, try also doing gem installs with lower versions of the gems you’re installing.

If macports is giving u trouble, uninstall macports. Install Homebrew.

If everything fails, just use a simple Ubuntu VM and go from there. You still have options.

There's probably going to be lots more pain related to any gems used in that app.

All in all seems like about time that app get some serious love and get updated at least to Rails 2.3 Ruby 1.8.7