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
Asset Pipeline for Dummies - coderberry The Rails asset pipeline is very powerful, but often misunderstood. At the Utah Ruby User Group, most of the attendees aren’t sure how to use it fully in their Rails app. It’s considered as one of the magic features that Rails offers. I reference the word asset a lot in this article. In this article, I want to simplify the asset pipeline so it is better understood. Purpose The asset pipeline has three goals: precompile, concatenate and minify assets into one central path. Moving Parts The asset pipeline is powered by two technologies: Sprockets and Tilt, the latter being a dependency of the former (look at your Gemfile.lock if you don’t believe me). Sprockets performs the asset packaging which takes the assets from all the specified paths, compiles them together and places them in the target path (public/assets). Tilt is the template engine that Sprockets uses. Asset Paths Rails applications default to having three possible asset paths. The Manifest Here are some directives that can be used:
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
12 Tips for the Rails Asset Pipeline | Sydney, Australia Ruby on Rails Developers Face it, you are a top developer, one of the best at your game, you eat lambda's for breakfast, refactor whole apps as an afternoon snack and bad code just trembles when you approach. You are at the top of your game and nothing stands in between you and the code you desire. Yet, the Rails asset pipeline still trips you up, not once, not twice, but just about every time you try and use it. Here's a list of things that I have learnt that aren't necessarily obvious, that can help you tame this wild and savage beast. 1. No CSS or JS files will be available to your app through the asset pipeline unless they are included in other files OR listed in the config.precompile directive (see #2 and #3 below). Only application.css and application.js are available by default of all the CSS and JS files. For example, you make a file in the assets folder called: app/assets/stylesheets/site.css.scss And you want to include this in your page. // = require_self // = require 'site' and then reference it with: 2.
#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) Customizing Devise views in Rails #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)