Hello folks,
It’s been a while since I updated the blog and rails has changed a bit since then. I thought I’d revise one of my previous posts: the one about uploading multiple images using paperclip. This time we’re going to be doing it using Rails 2.3.4. I’m going to be using the paperclip gem, [...]
Have you ever had to write conditional validations in your model? Have you ever found your self repeating the condition across several validations? Would you like to dry this code up a little? Well, this is how you could do it.
Example verbose code:
validates_presence_of :field_one, :if => :my_ubber_condition? validates_length_of :field_two, :if => :my_ubber_condition? [...]
Sometimes we need to update all of the records in our table with some information. Lets say for arguments sake that we need to update the “pages” table and set the “name” column to a certain value for all rows. We might be tempted to do this a couple of ways.
The first approach:
@pages [...]
I’ve seen this mistake made quite a few times by new comers to rails and thought I would address it here, in case someone stumbles upon it looking for a solution. Let’s begin by creating a simple one-to-many association between two models.
#gallery.rb class Gallery < ActiveRecord::Base has_many :exams end #photo.rb class Photo < ActiveRecord::Base [...]
Today, I would like to talk about adding data from an external file: example, from a .csv file. Lets say we have some info about “users” which we would like entered into the database. We can do this by using the fastercsv gem. Install it using ‘gem install fastercsv’. The format for such a [...]
Recent Comments
