Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Ruby's counterpart to Java's web.xml?

I'm working with Redmine for the first time and was able to successfully install it locally. I haven't used Ruby before and I come from a Java background.

I am able to run the application by going to -

http://localhost:3000/projects

The question is, where can I find the html file (if it exists) that corresponds to http://localhost:3000/projects. In Java, we can do this by looking at web.xml or the relevant Spring configuration file and see how the URL is mapped to a servlet or controller. How to do this in Ruby?

like image 557
CodeBlue Avatar asked Jan 26 '26 19:01

CodeBlue


2 Answers

The counterpart of web.xml is the routes.rb and the config.rb files in ruby. You'll find them in the config directory. The routes.rb defines which controller and action (much like servlets) will handle a certain request (URL). And since Rails has predefined conventions, all the html files go in the folders named after the controllers in the views directory and by convention the html file with the same name as that of the controller's action that has been invoked will be rendered as the response.

But all of this can be overridden if desired.

This is a nice place to start understanding Rails: http://guides.rubyonrails.org/

like image 145
Steve Robinson Avatar answered Jan 28 '26 12:01

Steve Robinson


Note that Ruby is not the same as Rails.

Ruby, like Java, is a programming language. It appeared in 1995. For example, the following is a script/program you can execute from the command line.

#!/usr/bin/env ruby
puts "Hello World"

Rack is a web server interface for Ruby. It handles the HTTP protocol, and allows one to write web applications in Ruby by making it easy to parse HTTP requests and send HTTP responses.

Rails is a web framework with powerful conventions, patterns, and tools for developing web applications in Ruby. Some part of it uses Rack. It appeared in 2004. Sinatra is an example of another web framework that uses Rack.

What's the equivalent of web.xml in Ruby?

It does not exist.

What's the equivalent of web.xml in Rack?

Probably config.ru.

What's the equivalent of web.xml in Rails?

config/routes.rb and config/application.rb. Please refer to Configuring Rails Applications.

Routes

To figure out which html file corresponds to http://localhost:3000/projects, look in config/routes.rb. If you see

resources :projects

then it is handled by the index action in ProjectsController with the view at app/views/projects/index.*.

like image 40
James Lim Avatar answered Jan 28 '26 11:01

James Lim