Dans le cas où votre application Rails tournant sous Passenger vous retourne cette erreur :
RAILS_ROOT is not a directory
Pensez simplement à vérifier qui est le propriétaire des fichiers rails…
Category Archives: Ruby On Rails
News from RoR world
I noticed 2 points that will change your life… Humm, only if you’re familiar with Ruby On Rails 🙂
- A very promising ruby on rails online documentation : http://rails-doc.org . Well documented, ajaxified, many examples and user comments !
- Named scopes in Rails 2.1 : imagine you can get all your recent active users by user.recent.active ? Take a look to this awesome feature.
ActiveScaffold : update_table
If you get this strange error :
ActiveRecord::RecordNotFound (Couldn’t find Structure with ID=update_table)
You have probably taken a start with “normal” scaffold and then tried to install activescaffold.
Simply edit your config/routes.rb and remove all map.ressources :
Hébergement Ruby On Rails gratuit
Un hébergeur qui propose un compte gratuit (pratique pour tester) et qui supporte Ruby On Rails :
Créer un hébergement Ruby On Rails sous un serveur Ubuntu
Un excellent tuto trouvé chez blogbangbang.com :
Je vous avait parlé il y a peu de la création d’une application RubyOnRails.
C’est bien mais un site c’est fait pour être hébergé quelquepart !
Et malheureusement Mongrel, on connait pas trop, on a l’habitude d’Apache…Et bien celà tombe bien, car c’est deux là vont très bien ensemble, il est en effet possible d’utiliser apache pour créer les virtual host, servir une partie des fichiers… et Mongrel pour le reste.
C’est même selon les spécialistes, le meilleur moyen d’héberger un site Rails actuellement.
C’est bien mais comment on fait ? Et bien je vous explique tout de suite la procédure sur une Ubuntu…Je pars du princpe que vous avez une application rails (la mienne s’appellera mynewsite)avec un serveur mongrel qui fonctionne en local(accessible sur
http://localhost:3000
).Avant tout, vous devez stoper votre serveur Mongrel afin de faire prendre le relais à Apache+Mongrel.
mongrel_rails stop //à éxécuter à la racine de votre aplication rails.Puis, si vous suivez ce tuto à la lettre avec un nom de domaine qui ne vous appartient pas, vous devez ajouter à votre fichier
/etc/hosts
le site désiré, afin de ne pas etre redirigé vers le vrai mynewsite.com.
La ligne devrait donc ressembler à ça :127.0.0.1 mynewsite.comDans un premier temps, nous devons activer le module proxy d’apache.
1- Activer le module proxy d’apache
sudo a2enmod proxy2- Créer le virual host
Le virtual host se crée comme n’importe quel autre avec apache2 : donc on va creer un nouveau fichier :
001-myewsite
dans le répertoire/etc/apache2/sites -available
(si vous hébergez déjà des sites, pensez à modifier le 001 en 002 ou plus).Le VirtuaHost doit donc ressembler à cela :
ServerName mynewsite.com
ServerAlias www.mynewsite.comProxyPass / http://www.mynewsite.com:3000/
ProxyPassReverse / http://www.mynewsite.com:3000
ProxyPreserveHost on#Fix for Apache bug 39499
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1# Ne pas rediriger les images, les CSS
# et les Javascripts vers Mongrel
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !# Et précisons le path où se trouve
# les images, les CSS et les javascripts
Alias /images /var/www/mynewsite/public/images
Alias /stylesheets /var/www/mynewsite/public/stylesheets
Alias /javascripts /var/www/mynewsite/public/javascriptsCustomLog /var/www/mynewsite/log/access “%h %l %u %t \”%r\” %s %b \”%{Referer}i\” \”%{User-Agent}i\””
ErrorLog /var/www/mynewsite/log/error
Explications :
Les deux premières lignes sont évidentes, on indique que ce virtual host fera tourner les sites demandé sur
mynewsite.com
etwww.mynewsite.com
.Notre appli tourne sur le port 3000 de la machine mais il est quand meme plus agréable de taper
mynewsite.com
quemynewsite.com:3000
pour acceder au site.
C’est le but des 3 lignes suivantes.Pour ce faire on utilise le mod_proxy d’apache (que l’on vient d’installer) en lui indiquant que les demandes faites sur
mynewsite.com
doivent être redirigées versmynewsite.com:3000
(cela se fait bien sur de maniere invisible et l’adresse dans la barre d’adresse ne changera pas.)On trouve ensuite 2 lignes qui permettent de résoudre un bug d’Apache lorsqu’il est associé à Mongrel.
Par la suite, on précise grâce à ProxyPass que les demandes pour les dossiers images, stylesheets et javascripts ne seront pas redirigées vers Mongrel (Apache est plus rapide pour ces contenus).
On indique donc à Apache le chemin vers ces dossiers grâce aux directives Alias.Enfin les directives CustomLog et ErrorLog indique à apache ou stocker les logs d’acces et d’erreur de notre site.
On les place logiquement dans le dossier log de notre application rails.
(il peut être nécessaire d’avoir créer les fichier et de leur avoir donné les droits pour l’utilisateur www-data).3-Configuration du proxy
Cette étape est souvent oubliée dans ls différents tutos que j’ai pu trouver sur le net. Pourtant elle est indispensable et c’est elle qui à à mettre en cause si vous vous retrouvez avec une erreur :
Forbidden You don’t have permission to access / on this server.Pour configurer notre proxy nous allons devoir modifier le fichier proxy.conf.
sudo nano /etc/apache2/mods-enabled/proxy.confet commenter la ligne
Deny from all
pour la remplacer parAllow from mynewsite.com
.4- relancer apache.
sudo /etc/init.d/apache2 restart5- relancer mongrel
mongrel_rails start -d //à éxécuter à la racine de votre application rails.Voilà on y est, vous pouvez désormais vous rendre sur
http://mynewsite.com
dans votre naviguateur et vous devriez y voir la page d’accueil de votre application.
RailsConf 2007 : presentations
All the presentations of the RailsConf 2007 are available here :
Resources about Ruby On Rails
A good starting point if you want a good panel of different websites discussing about or explaining Ruby On Rails :
Installation
Sometimes, the most time consuming part of learning a new programming language is simply installing a working version of the software. With help from these resources, you’ll have Rails up in no time.
If you’re interested in getting Rails to work on your own, you’ll need to follow the following steps:
- Ruby – First you need to download Ruby.
- Ruby One-Click Installer – If you’re having difficulty getting Ruby to run try this installer (Windows only).
- RubyGems – Then you need to download RubyGems (package manager).
- Ruby on Rails – Finally, download Rails.
Why do all of the work when someone else will do it for you? Here are two options for automatically installing Rails.
- Instant Rails – One-click Rails installer for Windows. Includes Ruby, Rails, Apache and MySQL all pre-configured and ready to run.
- Locomotive – Self-contained one-click Rails installer for Mac OS X.
These step-by-step guides will walk you through the installation process.
- How-tos Installation – If you get stuck, or want to try to install Ruby to a more obscure operating system, look here.
- Fear of Fish: Getting Started – Walkthroughs for Rails installation on Mac OS X, Windows and Linux.
- Building Ruby, Rails, LightTPD and MySQL on Tiger – Instructions for installing Rails on Mac OS X (Tiger).
- GettingStartedWithRails – After you’ve installed Rails you still have a few more steps before you’re ready to build your first application. This article walks you through those steps.
If you’re looking to build Rails apps remotely (of course you are!) you’ll need a hosting company that supports Rails. These Web sites list some of your options.
- RailsWebHosts – Extensive hosting list provided by the official Ruby on Rails Web site.
- Rails Hostings – An excellent breakdown including user reviews of the various Rails hosts.
Tutorials
Once you’ve installed Rails it’s time to start coding. Here are a few starting points for you.
After you’ve installed Rails you should be ready to start developing applications. The following links are starting places for learning the foundations of Ruby, Rails and building your first apps.
- Try Ruby! – A simple interactive tutorial teaching you the basics of Ruby in 15 minutes.
- Ruby User’s Guide – Complete step by step guide for learning Ruby.
- Learning Ruby – Uses program examples to teach you the basics of Ruby. Draws parallels between other languages to show you what makes Ruby unique.
- Hackety Hack: the Coder’s Starter Kit – An interactive program designed to teach students how to program Ruby.
- Tutorial – This tutorial walks you through building your first Rails app.
- Using Ruby on Rails for Web Development on Mac OS X – Apple’s guide for developing your first Rails application.
- Learn Ruby on Rails: the Ultimate Beginner’s Tutorial – A solid Rails tutorial with a lot of explanation rather than just mindless code.
- A Many-to-Many tutorial for Rails – A walkthrough for building your first Rails app.
- Getting Your Feet Wet With Ruby on Rails – A beginner’s guide to taking advantage of Rails’ unique design. Includes information for creating the SQL database and scaffolding.
- Beginners Guide to Rails, part 1 – Shows you how to get your Rails database off the ground.
- Really Getting Started in Rails – Brief overview of the schematics of a Rails app.
- Basedex: Ruby on Rails – A massive glossary of Ruby on Rails links.
- How-tos – An extensive how-to library containing sample programs.
Once you’ve mastered the beginner tutorials, check out this section for information on taking your Rails experience to the next level and building more dynamic applications.
- 19 Rails Tricks Most Rails Coders Don’t Know – Programmer Peter Cooper’s article containing various Rails hacks.
- Railscasts – Videos teaching you advanced Rails techniques.
- Ajax on Rails – A brief tutorial on adding Ajax to your applications.
- How to paginate, sort and search a table with Ajax and Rails – More information on the Ajax/Rails relationship.
- Ruby on Rails Caching Tutorial – Helping you to master the fine art of caching in Rails.
- How-to: Build a secured web application with Ruby on Rails – One of the most basic requirements with Rails is to have a secure Web application. Here is a breakdown for creating that secure environment.
- A complete turbogears spoliation: how-to build a wiki in 20 minutes (well I did not time it) – Since wikis are one of the hottest trends on the Web today, we figured you might want to see how to build one yourself.
- Agile RSS Aggregator in Ruby – A brief tutorial for developing a RSS aggregator.
Books
Books are key items in every programmer’s arsenal. Unfortunately, books are often difficult to navigate, bulky and may not have all the pieces of information you’re looking for. Lucky for you, we’ve found several Ruby and Rails books online that have the information you need, making them excellent additions to your library.
- Programming Ruby: The Pragmatic Programmer’s Guide – A complete reference for Ruby including sample program input and output.
- Why’s (poignant) guide to Ruby – A very casual and easy to read Ruby guide with comics and examples.
- Learn to Program – An excellent book for beginners; uses Ruby to teach the fundamentals of programming.
- Ruby on Rails Books – A group of 8 books that walk you through various Rails programs.
Blogs
You’re not truly immersed in Rails unless you’re reading another programmer’s blog. Here are a few of our favorites.
- Web 2.0 with Ruby on Rails – Fantastic blog containing multiple Rails tutorials and links.
- Rails Envy – Excellent resource for advanced Rails programmers.
- The Rails Way – Instructional Web site for learning the “best practices” in Rails application design.
- Ruby Inside – A very informative blog listing the happenings and new applications emerging in the Ruby community.
- Ruby Underground – Contains information for advanced Ruby programmers.
- Ruby on Rails Security Blog – Focuses on developing security apps with Rails.
- Web On Rails – Resource for advanced Rails programmers.
- Riding Rails – The official Rails blog.
- Ruby On Rails Blog – Contains multiple instructional Rails articles and useful links.
Forums
Sometimes we get so stuck, that the only place we can turn to is our all-knowing peers. Here are a few online communities ready to help you out.
- Ruby Forum: Ruby on Rails – Extremely active forum containing everything on Ruby.
- Rails Forum – A great source for helping you debug your apps.
- TextDrive Community Forum/RubyOnRails – An alternative Rails forum.
- #rubyonrails – Rails IRC chat.
Cheat Sheets
If you’re the type of coder that likes to tackle multiple projects and different languages at a time, you might find yourself confusing the different syntaxes. Here are a few cheat sheets to keep you on track.
- RubyOnRails-Cheetsheet – A 14 page Rails cheat sheet (PDF).
- InVisible Ruby On Rails Reference – Example driven Rails cheat sheet.
- Ruby on Rails Cheat Sheet Collectors Edition – A simple Rails cheat sheet with examples.
- Ruby Cheatsheet – A basic Ruby cheat sheet listing all of the most used features (PDF).
- Ruby QuickRef – Example driven Ruby cheat sheet.
API
If you’re unsure how operate a particular method or would like to know the capabilities of a particular class check out these documents.
- RDoc Documentation – Ruby’s core API.
- Ruby Standard Library Documentation – Ruby’s stdlib API.
- Rails Framework Documentation – Rails API.
- Ruby on Rails Manual – Rails API.
Miscellaneous
Our list wouldn’t be complete if we left out these Web sites.
If you want to check out what everyone else is doing with Rails, these Web sites are for you.
- DZone Snippets: Rails – Rails snippets.
- Ruby Forge Snippets – Ruby snippets.
- RubyForge – The open source Rails Web site.
- RubyRoll – Displays recent articles from popular Rails blogs and resources.
- Plugins in Ruby on Rails – Directions for installing Rails plugins. Includes extensive list of plugin repositories.
- Agile Web Development Plugins – Nearly 600 Rails plugins.
Here are some of our favorite links illustrating why Rails is such a solid language.
- Ten Reasons Ruby Is Cool – A programmer gives 10 reasons why Ruby is their programming language of choice. (Part 2.)
- Ruby From Other Languages – Compare Ruby to other programming languages.
- Working With Rails – Maintains a database of Rails programmers, projects and their Web sites.
- HappyCodr – A showcase for Web sites designed with Rails.
http://www.softwaredeveloper.com/features/74-ruby-on-rails-resources-tutorials-050207/
IRB completion
Ruby vs Java
Un article avec évidemment un parti pris, mais qui met tout de même en avant quelques avantages certains à programmer en Ruby…
http://www.rubyrailways.com/sometimes-less-is-more/
Quelques perles :
Java:
Class Circle private Coordinate center, float radius; public void setCenter(Coordinate center) { this.center = center; } public Coordinate getCenter() { return center; } public void setRadius(float radius) { this.radius = radius; } public Coordinate getRadius() { return radius; } end;
Ruby:
class Circle attr_accessor :center, :radius end
ou encore :
Java:
new Date(new Date().getTime() - 20 * 60 * 1000)
Ruby:
20.minutes.ago
Control.Modal
With this library, based on Prototype Javascript library, you can display a lot of modal box on your web interface :
- Relative Modal – Opens a local modal window relative to the position of the link. With custom width and height.
- Centered Modal – Opens a local modal window in the center of the screen. Adds CSS classes to the container and overlay.
- AJAX Modal – Opens a modal window that is the response of an AJAX call.
- iframe Modal – Opens a modal window that contains an iframe.
- Lightbox One – Opens a modal window with an image inside.
- Lightbox Two – Opens another modal window with an image inside.