In episode 362 we showed how to export database records to a CSV or Excel file. Since then there have been a number of requests for an episode showing how to import records from these types of files so that’s what we’ll cover in this episode. We’ll do this by adding a form to the bott...
A good multistep form remembers the input between steps, allowing users to go backwards and forwards through the pages without losing any of the information they have entered. If you just want to break up a big form to simplify the user interface you may could use a combination of Jav...
Above is a page from a site that has three different models: articles, photos and events. We’d like to enhance the site so that its users can add comments to an article, a photograph or an event. If we were just adding comments to one of the models, say articles we’d create a Comment ...
Stripe needs two API keys so that it knows which account it’s working with. We’ll store these in a new stripe.rb initializer file in the application’s /config/initializers directory. The keys we need to store here are the secret test key that’s shown in our account page and the public...
models we’ll move on to the survey form. What we want to do here is add fields for each of the survey’s questions to the form. We can use the fields_for method to manage associated fields in a form, passing it the name of the associated model and then loop through all of the associate...
we covered Declarative Authorization . While it is an excellent authorization plugin for Rails it can be a little heavy for simpler sites. After writing the Railscast on Declarative Authorization Ryan Bates looked for an alternative solution and, failing to find one that suited his ne...
If we run the specs now we’ll have two passing specs, so it looks like our code works as expected. If we were doing test-driven development we’d start with a failing spec and then write code to make it pass and this is one of the advantages of test-driven development as it ensures tha...
Next we need to write the code that will deliver the email when the user is created. Some people like to use a Model Observer to do this, but we’re going to keep the code in the controller layer. The reason for doing it this way is that if we do use an observer and then create User ob...
26: Hackers Love Mass Assignment (view original Railscast) Other translations: Other formats: Mass assignment is something most Rails programmers make use of as it provides an easy way to populate the properties of a model object from a form. Unfortunately its simplicity can make it a...
330 Better SASS With Bourbon If you are tired of the browser vendor prefixes in CSS, take a look at Bourbon. It provides Sass mixins and functions to make CSS more convenient. Tags: plugins views 328 Twitter Bootstrap Basics Twitter Bootstrap can help make beautiful web apps quickly b...
292 Virtual Machines with Vagrant Vagrant allows you to run your Rails application and all of its dependencies in a portable, sharable environment. Use for development, set it up as a staging server, or experiment with a production setup. Tags: tools 290 SOAP With Savon Communicating ...
I really like Ryan Bates’s Railscasts , but videos aren’t the easiest thing to search through when you’re trying to search for a single tip or line of Ruby code to add to your own site. ASCIIcasts are text versions of each Railscast, each with a link to the original video. I hope you ...
When JavaScript plays a large part in a Rails application it often becomes necessary to pass data from the app on the server to JavaScript to be used by the client. In this episode we’ll explore some techniques for doing just that. Below is a simple page from a simple Rails applicatio...
215: Advanced Queries in Rails 3 (view original Railscast) Other translations: Other formats: This episode will cover advanced queries in Rails 3. In episode 202 [watch , read ] we covered the additions to ActiveRecord queries in Rails 3; here we’ll carry on from there and show you so...
There’s a great article on the Rails Rumble blog that explains in detail how to add OmniAuth to a Rails application. The article shows you how to create authentication from scratch, but here we’ll show you how to integrate OmniAuth into an application with an existing authentication s...
Unfortunately there is no easy solution to this problem. What we’ll do is keep the validation and redirect the user to a form where they can fix any problems if the validation fails when we try to save the new user. We’ll change the code in create so that if the validation fails when ...
. This works by creating a number of named scopes that can be called on any ActiveRecord model to search against that model’s attributes. Given, say, a User model with a username attribute, Searchlogic lets us use methods such as username_equals , username_does_not_equal , username_be...
Episode 193 [watch , read ] was all about tableless models. In that episode we created a model that used some of ActiveRecord’s features but which didn’t have a database table behind it. The technique we used was quite a hack as this is something that ActiveRecord wasn’t designed to d...
A few weeks ago episodes 235 [watch , read ] and 236 [watch , read ] covered OmniAuth. OmniAuth provides a great way to integrate third-party authentication services such as Twitter and Facebook into your Rails applications. The scenario we presented in those episodes was rather compl...
showed how to generate PDFs with the PDF::Writer gem. That is still a good way to generate PDF files, but there is now a much newer gem called Prawn available and all the cool kids are using that. Prawn is a very fast Ruby PDF generator that is installed as as gem, but it isn’t specif...
In the previous episode we created a role-based authentication system. On the application’s sign-up page a series of checkboxes allowed a user to assign themselves to one or more roles. The application has a Role model in which the roles are defined and a many-to-many relationship bet...
Any medium or large-sized website probably has a large amount of CSS spread across one or more stylesheets and the chances are that there are selectors in those stylesheets that are no longer used on any of the pages in that site. These selectors should be removed but they rarely are ...
. It uses a different approach from Restful Authentication in that it doesn’t generate controllers or views but just deals with the code to handle the authentication for your users. Because of that it can take a bit longer to get your application running under Authlogic, as you have t...
To demonstrate Rack Middleware we’re going to use the simple e-commerce application seen in previous episodes. We’d like to know how long each request takes to process so we’re going to use Middleware to inject an HTML comment into each page that contains the processing time. This is ...
This line is added by default in a new Rails 3 application. It’s easy to forget to add filtering into an application so it’s a nice feature to have installed by default. It will of course only filter password parameters as it stands and will need to be altered if other parameters such...
To use Bourbon with Rails’ asset pipeline we’ll need to change the way that the default application.css file works. By default this file will use a Sprockets manifest to load each of the other stylesheet assets. The problem with this is that Sprockets compiles each SASS file into CSS ...
Back in episode 33 [ watch , read ], we made a plugin for Rails. A more popular option for extending Rails’ functionality now is to make a gem, and that’s what we’re going to do in this episode. Let’s say that we’d like to be able to generate a unique token for an ActiveRecord model. ...