Tag Archives: ruby

RubyMotion Launch Image

There is no way to specify a launch image directly in the Rakefile with the standard RubyMotion config options. The launch image is considered an advanced configuration option and can be set using the advanced plist settings technique which is detailed here: Advanced Info.plist Settings.

Basically you just use the app’s info_plist property to set any keys or values necessary in the Info.plist file that RubyMotion does not expose configuration options for.

I added this to my Rakefile to make it happen:

app.info_plist['UILaunchImageFile'] = 'launch'

Here, ‘launch’ is the base name for the images. This means that the filenames would look like this:

launch.png : 320 x 480px
launch@2x.png: 640 x 960px
launch-568h@2x.png : 640 x 1136px

User Administration Scaffold for Devise

Here is a quick way to add a user controller and views to a rails app that is using Devise for authentication. First, create the controller and views for the model which Devise created for you. You can do that with the scaffold_controller generator.

rails g scaffold_controller users

Now you’ll have the basic user CRUD abilities.

You’ll need to add a password_confirmation password field to the form if the generator didn’t do it for you. The main problem I’ve encountered is that you always have to type in the password and the confirmation when updating a user model. In order to prevent this you can override the password_required? method in the user model.

def password_required?
  (!password.blank? && !password_confirmation.blank?) || new_record?
end

Another nice thing I like to do is create a rake task to create a new user. This can be used on a new database to create a user to log in with. I created a file called auth.rake in lib/tasks.

namespace :auth  do
  desc "Create first database user"
  task :create_first_user => :environment do
    u = User.new
    u.full_name = "First User"
    u.email = "admin@example.com"
    u.password = "password"
    u.password_confirmation = "password"
    u.save

    puts "You can log in with email: '#{u.email}' and password: '#{u.password}'"
  end
end

You can run the task with the command:

rake auth:create_first_user