I'm a compsci student who wants to get learn a little about web development -- I learn best by doing. I know basic html/css/php/javascript/xml, but since Ruby is one of my favourite scripting languages, I figured I'd learn Ruby on Rails.
I'd like to build a basic website for a friend's club at school that just provides information about their organization and services they offer, and have an admin panel on it that contains a very basic inventory system (item, number in inventory, cost -- that's it) in order to learn Ruby on Rails. I'll be hosting it on a computer on campus -- so I don't have to worry about hosting.
This might sound a little silly, but as someone who's never built a website themselves, I was wondering how exactly one goes about it with rails -- like, how do I make a basic layout for the main part of the site -- with things like "Home, About Us, Services, Contact, Club Executive" along the top? Do I have to make it in html and put it in the "view" section? The tutorials I've read on rails (Getting Started With Rails) actually make the basic inventory system seem easy, compared to this part, using a lot of the built in functionality of Rails and scaffolding. The Rails documentation is a tad bit confusing.
The "official" Rails book is quite good if you want to start building Rails applications. link
But actually is something like this:
rails applicationnameruby script/generate controller mainNow you have a controller in app/controllers, called main_controller.rb. Here you can insert the actions you want this controller to respond. If you don't want the controller to do anything just show the view, then leave the method empty.
class Main < ActionPack::Controllers def index end def about end def contact end (...) end
Now you got a controller that will respond to index, about and contact.
app/views/main/index.erb (and others, like about.erb)Alternatively you can use a layout, that you have to define in app/views/layouts/main.rhtml In this layout use HTML, but wherewer you want to include the view, write <%= yield %>
Example:
<HTML> <BODY> <%= yield %> </BODY> </HTML>
You can include this layout in the controller by writing layout :main in the class (before the method declarations)
ruby script/server in the root of the app you can access the pages you've created. They will be static of course, but this might get you going. You have to add models and some logic to your controllers to advance. I advice you to check the book I linked if you're interested in more, or check the alternatives of rails like merb (http://merbivore.org) which has some nice features and is usually faster, but lacks the maturity of rails.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With