Outils pour utilisateurs

Outils du site


issue79:c_c

Ceci est une ancienne révision du document !


Early in December I was spending some time working on a website that will eventually become my website for my freelance IT business. I started off using Bolt CMS and ended up with a design I quite liked, and overall, Bolt did everything I wanted. However, it did a lot more than I needed as well, and I have slight reservations for using a blog-oriented CMS to manage the content of a web page. Instead, I decided to give Ruby on Rails a shot, to see which option I would ultimately go with. I had previously spent a while learning both Ruby and Ruby on Rails, so jumping in wasn't quite as daunting. This month's article is for anyone hesitating about diving in, and for anyone interested in web design who would like to pick up some new skills. Prerequisites The ruby package must be installed before using Rails. The current one in Ubuntu is version 1.9.2 (package: ruby1.9.1). The current version is actually 2.0.0-p353, so it may be better to install ruby-rvm (ruby version manager), and use that to install/manage your ruby versions. For anyone who needs to install it in other operating systems too, there are good instructions here: https://www.ruby-lang.org/en/downloads/ Rails installation instructions: http://rubyonrails.org/download

Ruby on Rails – What is it? Ruby on Rails is a framework designed in Ruby to make the generation of complex websites much easier. It's designed with the idea in mind that a programmer can focus on convention over configuration, while still designing the website they originally had in mind. Ruby on Rails – Why should I try it? • By default it uses SCSS for its stylesheets, allowing for cleaner formatting in your stylesheets (it's automatically parsed to css when running the server). • Integrates a server setup, which can be started with “rails server” or “rails s”, and polls for changes to the files, while serving up your website on localhost:3000 (port 3000, by default). Naturally, this can also be used in a production environment with an actual domain. • Allows for easy extensibility by editing the Gemfile. • Has modules for certain tasks (i.e. User authentification) which you can easily add to your own project, and helps to avoid feature overload. • You can create your own classes and controllers, so that only items you actually use are saved in your database. • Error handling – This is a bit subjective, but I find that Rails' approach to throwing errors and debug information is a lot more helpful/cleaner than most other web-based languages. • Large community – odds are you'll be able to find a solution to most of your problems online, and some areas may even have Rails/Ruby meet-ups. • Integrates with Git very well, allowing for clean revision control of your website's code. It can also be used to upload your site to hosts like Heroku, without the need to use FTP. • Includes a routing table, allowing you immense control over the URL formatting and restrictions.

Possible hardships: • Very programming-focused – if this isn't your forte and you're not interested in learning, you may very well struggle. • Requires a basic knowledge of Ruby – since Rails uses the Ruby syntax for controllers, models and helpers, it's highly recommended you have a working knowledge of it. However, something like http://tryruby.org/ could be sufficient, if you're willing to refine your knowledge as you work in Rails. • Unless you follow a tutorial for your first project, you may run into issues where you're unsure what to Google, due to the errors being specific to your custom models. • The rails generate command can be slightly confusing at first, especially when it results in rake db:migrate errors. However, once you work your way through one error, you should have a good understanding of how to fix future ones. • If you don't know about SCSS, you will lose out on the benefit of it, but it won't impact your CSS generation.

You've sold me! Where do I start? The first stop I'd recommend is http://tryruby.org, in order to learn/freshen up on Ruby. Once you've completed that, Code School also offers a free course in Rails, called Rails for Zombies (http://railsforzombies.org). While it may seem silly at points, it is actually a great resource for an introduction to Rails. There are also countless books that cover Ruby on Rails (admittedly, I haven't read any, and as such don't feel I can make a recommendation). Once you've read up on Rails and have done a tutorial of some sort, be sure to pick out a specific thing you'd like to achieve (i.e. Design a class/controller to handle pages and their content). Then look into the rails generate scaffold command. My only tip here is to make sure you integrate all the variables you'll need from the get-go in the scaffold command. An example command could be: rails generate scaffold Page title:string content:string slug:string This will generate the controller, model and views required for Page, and configure it to have a title, content, and slug attribute in the database, which you can input through the edit page. Since this article isn't intended to be a detailed how-to, I will leave you with just two more hints: •In the above example, after running the server, you can see your pages by going to http://localhost:3000/pages • Once you've used the scaffold command and have the files, it works best if you then generate specific controllers or models as you need them. To see a full list, type rails generate -h

It still seems kind of daunting - can I really do this? Titre : Ruby on Rails If you want a success story, the one that first jumps to mind is the creator of Freelancify, who learned Ruby on Rails in 12 weeks (specifically, from the time he began learning Ruby on Rails and the time he put Freelancify online was 12 weeks). According to his blog post, he wasn't a programmer at all before jumping into Ruby on Rails. Source: http://www.jamesfend.com/learned-ruby-rails-12-weeks-launch-freelancify Will you be doing a tutorial on how to set up Rails? While I find the Ruby on Rails documentation is excellent, and there are some guides online as well, I can understand if some people prefer an up-to-date step-by-step guide from me. If that's the case, let me know in an email at lswest34+fcm@gmail.com and I will happily cover setting up Rails 4.0.2 and getting a project started. As always, I hope you've found this article interesting, and that I have enticed one or two of you into trying Ruby on Rails. If you have any comments, questions, suggestions or requests, you're welcome to contact me at lswest34+fcm@gmail.com. I'd also be happy to hear about any experiences with Ruby or Ruby on Rails you've had.

issue79/c_c.1395415698.txt.gz · Dernière modification : 2014/03/21 16:28 de frangi