Updated for Rails 3: Using Paperclip and jpegcam to get pictures from your webcam into Rails View the complete source code for this post Here’s how to get pictures from your webcam into Rails using the Paperclip plugin and jpegcam. It is an update of the Rails 2.3.x version of this post. What we will do is create a Photo model and a Photos controller with actions new, upload and create to take care of the image creation. Start by creating a new Rails application: Create the Photo model: Create the Photos controller: Edit config/routes.rb to contain a photos resource: Download jpegcam and put webcam.js in your public/javascripts folder and webcam.swf and shutter.mp3 in your public folder. Edit the layout file app/views/layouts/application.html.erb and insert the following HTML inside the <head>-tag just below the other javascript_include_tag: Next, create app/views/photos/new.html.erb and make a div for the webcam contents: And the actual webcam javascript: That will run the actual webcam so you can see yourself :) But for taking a picture, we’ll need to add the following button: Then run:
Nested model form in Rails 4 - iRoller's notes Quick guide on how to build a simple survey application using Rails 4 and simple_form. There are some good topics on it on RailsCasts (Rails 3 and no simple_form): And also a bunch of questions answered on stackoverflow. Please use the official documentation to understand things you’re doing I just want to cover the most basic setup. I’m going to use haml instead of erb and simple_form for creating forms. Install all required gems using bundler We’re going to use has_many and belongs_to associations as the simplest for our case. Create additional columns First of all we need to create and additional column inside anwers and questions database tables containing an ID of associated object Run migrations Run migrations to get tables actually created Create associations between models Then we need to add the associations to our models. Edit app/models/answer.rb Edit app/models/question.rb Edit app/models/survey.rb Edit controllers Edit views
Rails Routing from the Outside In 1 The Purpose of the Rails Router The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views. 1.1 Connecting URLs to Code When your Rails application receives an incoming request for: it asks the router to match it to a controller action. 1.2 Generating Paths and URLs from Code You can also generate paths and URLs. and your application contains this code in the controller: and this in the corresponding view: then the router will generate the path /patients/17. 2 Resource Routing: the Rails Default Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. 2.1 Resources on the Web Browsers request pages from Rails by making a request for a URL using a specific HTTP method, such as GET, POST, PATCH, PUT and DELETE. it asks the router to map it to a controller action. 2.2 CRUD, Verbs, and Actions 2.3 Path and URL Helpers 2.5 Singular Resources
Pradeep's Ruby on Rails Blog | RoR for developers bootstrap-ruby/bootstrap-editable-rails Ruby on Rails Tutorial | Softcover.io Welcome to the Ruby on Rails Tutorial. The goal of this book is to be the best answer to the question, “If I want to learn web development with Ruby on Rails, where should I start?” By the time you finish the Ruby on Rails Tutorial, you will have all the skills you need to develop and deploy your own custom web applications with Rails. You will also be ready to benefit from the many more advanced books, blogs, and screencasts that are part of the thriving Rails educational ecosystem. (Note: The present volume is the Rails 4.0 version of the book, which means that it has been revised to be compatible with Rails 4.0, but it is not yet a new edition because the changes in Rails don’t yet justify it. Box 1.1. This is a (nearly) comprehensive list of differences between the 2nd edition of the Ruby on Rails Tutorial and the present version. In what follows, each item includes a reference to a section or code listing with an example of the change in question. Box 1.2. 1.1 Introduction Browsers
Getting Started with Rails 1 Guide Assumptions This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. Rails is a web application framework running on the Ruby programming language. If you have no prior experience with Ruby, you will find a very steep learning curve diving straight into Rails. Be aware that some resources, while still excellent, cover versions of Ruby as old as 1.6, and commonly 1.8, and will not include some syntax that you will see in day-to-day development with Rails. 2 What is Rails? Rails is a web application development framework written in the Ruby programming language. Rails is opinionated software. The Rails philosophy includes two major guiding principles: Don't Repeat Yourself: DRY is a principle of software development which states that "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." 3 Creating a New Rails Project 9 Security
Working with nested forms and a many-to-many association in Rails 4 - Created by Pete Recently a project I was working on needed a many-to-many relationship that would also store some extra data in the pivot table. Rails provides helpers to make working with this sort of relationship a breeze but when you start to include the nested forms and requirement to add data to that connecting table the solution may not be that obvious. I'll be using Rails 4, the code will be the same for Rails 3.2 for the most part the major difference is Strong Parameters is now used in place of attr_accessible. For this example I'm going to use a Survey application, unfortunately this was a survey done in the street on paper and now the results need to be manually added to the system. Each Survey will have some Questions, these Questions will be answered by a Participant. So in this example we need an Answers table to be our many-to-many table that will link our Participant to our Question and keep the Answer the participant provided in an additional column. So let's start a new Rails application.
Setting up PostgreSQL for Ruby on Rails development on OS X | Will writes One of the reasons people used to give for using MySQL over PostgreSQL (just ‘Postgres’ from here on in) was that Postgres was considered hard to install. It’s a shame, because it’s a great database (I’ve been using it for personal and some work projects for years, like my current side project, sendcat). Luckily it’s now really simple to get it going on your Mac to give it a try. What this guide is This is a guide to getting PostgreSQL running locally on your Mac, then configuring Rails to use that for development. What this guide is not An advanced PostgreSQL guide.Suitable for using in production.Anything to do with why you might want to use PostgreSQL over any other database. Installation You can get binaries for most systems from the Postgresql site, but it’s even easier if you’ve got homebrew installed, if you haven’t got homebrew it’s worth it, pick it up here. With homebrew just run: $ brew install postgres You will get a load of output, but the most important part is this: $ rails s
#264 Guard Guard watches files and runs a command after a file is modified. This allows you to automatically run tests in the background, restart your development server, reload the browser, and more. Download: source codeProject Files in Zip (260 KB)mp4Full Size H.264 Video (17 MB)m4vSmaller H.264 Video (10.5 MB)webmFull Size VP8 Video (24.8 MB)ogvFull Size Theora Video (23.6 MB) #336 Copycopter Copycopter provides a nice interface that clients can use to edit the text in a Rails application. Learn how to deploy a Copycopter server using Heroku and integrate it in a Rails application through I18n. Download: source codeProject Files in Zip (84.4 KB)mp4Full Size H.264 Video (20.9 MB)m4vSmaller H.264 Video (9.79 MB)webmFull Size VP8 Video (9.75 MB)ogvFull Size Theora Video (20.8 MB)
Création d'un blog avec le framework Padrino - 1ère partie : les bases | Julien Itard - Blog A l’heure où j’écris ces lignes, Padrino est en v 0.11.0. Si ce n’est déjà fait, je vous invite à lire mon article présentant ce framework. Dans cette première partie du tutoriel consacré à la réalisation d’un blog à l’aide du framework Padrino, nous allons poser les bases de notre application qui servira de support à votre apprentissage. Sources Vous pouvez retrouver les sources finales de cet article ici. Les identifiants de l’administration sont : adresse mail : admin@admin.commot de passe : admin Installation Avant de commencer à développer notre application, vous devez avoir préalablement installé sur votre poste Ruby ainsi que Rubygems. Pour plus d’informations sur l’installation, je vous invite à consulter le guide officiel. Génération du projet Pour créer un projet sous Padrino, la meilleure chose à faire est d’utilisée le générateur en ligne de commande qui est extrêmement pratique en bien des situations. $ padrino g project blog -e haml -c sass -s jquery -d activerecord -b Conclusion
Tutorial Rubyonrails 3 - Partie 3 - Création des relations entre les models (détail relation et migration) - Développeur Web RoR Partie 3 – Rails3 - Création des relations entre les models (détail relation et migration) N’hésitez à mettre des commentaires / à corriger mes fautes / à rajouter des choses ! Rails intègre un système de migration. Donc si vous avez besoin de renommer un champ, de rajouter une table, de rajouter un champ, de supprimer un champ vous devez créer une migration. Les migrations se trouvent dans monblog/db/migrate . Pourquoi parler des migrations ? Eh bien, nous avons les models, nous savons les manipuler. Souvenez-vous dans la partie 2 : reader : celui qui laissera un ou plusieurs comments sur un post. post : un article du blog, il possède plusieurs comments. comment : les commentaires des readers sur un post. Nous allons donc créer une migration pour ajouter les clés étrangères oubliées (volontairement) lors du rails generate model. Donc créons une migration pour ajouter les clés étrangères: rails generate migration add_foreign_keys Un peu de lecture
Ruby on Rails 1.2.2, les migrations Voici la suite du précédent tutoriel sur Ruby on Rails publié sur ce même blog ou nous avons mis en place une application de gestion de contacts rudimentaire. Migration de schéma de base de données Imaginons que nous voulions gérer une liste de sociétés, et lier chacun de nos contacts à sa société... Il va nous falloir modifier notre base de données en ajoutant une table companies et une clé company_id dans la table contacts. Cela peut s'avérer compliqué puisqu'elle contient déjà des données... même si en l'occurence il ne s'agit pour l'heure que de données de test. Rails et plus particulièrement ActiveRecord proposent un outil de gestion des évolutions du modèle de données intelligent, les migrations. Dans chaque classe de migration de schéma, une méthode up appliquera des modifications au modèles tandis qu'une méthode down permettra un rollback des modifications vers une version antérieure. (j'en ai profité pour répartir le patronyme sur deux champs, nom et prénom) Le fichier .