Showing posts with label Ruby on Rails. Show all posts
Showing posts with label Ruby on Rails. Show all posts

Saturday, 22 October 2016

Rails woes on Windows 10

The Rails community isn't strong on support for Windows based machines.

The github repository RubyOnWindowsWoes contains the source and issues found.

This note is to remind me how I eventually solve the problems!

Sunday, 27 July 2014

Adding Firstname, middle name and last names to a Ruby on Rails app

I was wanting to add first name, middle name and last name columns to a Ruby on Rails application (specifically the Rails-Devise tutorial from RailsApps).

After a couple of hours working through various sites I came up with three migrations:

timestamp_add_first_last_to_users.rb
class AddFirstLastToUsers < ActiveRecord::Migration
  
  def self.up
    change_table :users do |t|
      add_column :users, :first_name, :string
      add_column :users, :middle_name, :string
      add_column :users, :last_name, :string
    end
  end
  
  def self.down
    remove_column :users, :first_name
    remove_column :users, :middle_name
    remove_column :users, :last_name    
  end    
end

timestamp_update_names_to_users
class UpdateNamesToUsers < ActiveRecord::Migration
  def up
    User.all.each do |user|
      na=user.name.split(" ")
      nc=na.size
      user.first_name=na[0]
      user.last_name=na.last if na.size>1
      user.middle_name= na[1..na.size-1].join(" ") if na.size>2
      user.save!
    end
  end
  
  def down
    User.all.each do |user|
      user.name = [user.first_name, user.middle_name, user.last_name].compact.join(" ")
      user.save!
    end
  end
end

timestamp_remove_name_from_users.rb
class RemoveNameFromUsers < ActiveRecord::Migration
  def up
    remove_column :users, :name, :string
  end

  def down
    add_column :users, :name, :string
  end
end

This works, but is probably not the best solution.

If you have an easier way, please feel free to let me know.



Friday, 6 April 2012

Fuel on Rails - the Static Pages

Progress!

screenshot of the contact page
I've made a little progress with the app, but it has felt like mostly taking backward and sideward steps working out the differences between erb and haml.
Static pages for the site have been setup, with a fairly plain gray colour scheme that needs something doing to liven it up a little.

A logo

I do have some ideas for a logo, and may resort to watercolours while I create some designs. I'll postpone deciding on a site colour scheme until I do create a logo: it would be a shame to have to change it more than once.
I'm having a debate with myself about the app title - perhaps "Fuel on the Road" might be better. I haven't decided if I'm winning or losing the debate though.

Signing up victims users

Next step is to get a signup and signin process set up. This is going to need careful thought, for the people like myself who forget passwords (perhaps I should just keep to using one password everywhere).

Fuel: a Ruby on Rails app

After completing the Software as a Service course and the Ruby on Rails tutorial guide I thought it was about time to start putting what I had learned into practice.
I'd spent several days thinking about what I wanted to create, had several complicated ideas then (prompted by filling the car with petrol) decided on an app to monitor fuel consumption.
So far I have created some screen layouts while thinking about what I want the app to achieve.

Initial Screen layouts

Homepage

There will be a homepage with possibly some statistics on the data held, although what I don't quite know what - perhaps something line the total spend on fuel in the past month compared to 12 months ago.

Sign up

A means to register on the site. Every site needs one, unless all the data is to be made public. I didn't seriously think about that at all.

Sign in

A means for a user to recover a forgotten password would be helpful here, it's a feature I certainly have used several times on various websites.

Users homepage

To show details of the vehicles operated by the user. Initial builds may restrict to a single vehicle.
Summaries of the fuel usage to be included here.

Vehicle details

The screen to show the details of fuel used for the vehicle.
A history of the fuel used and some comparisons with 3/6/12 months ago might be interesting.

Fuel upload

The means of adding the fuel used to the database.
Not much point without including this!

What else?

The means to allow another user to upload fuel details might be useful (I know it would for me), and that would need some form of authorisation scheme, along the lines of friend requests on social networking sites.

Top Down Design

I intend to use a combination of Cucumber feature lists and rspec specifications to ensure the app is working the way I intend. This will also help reduce the risk of a change breaking the site without being noticed.
I did notice something interesting: I have written one user script for logging into the system, and I currently have 100% code coverage. Although as I don't have any lines of code in the system, that's quite easy to achieve.

The next steps

They are going to be to create further rspec and cucumber test scripts and implement the user sign in model, followed by adding vehicle details and then adding fuel loads.
I have a fairly comprehensive list of all of the fuel I have put into my current car going back several years since I first bought it (about a week before I started dating my girlfriend).
The source code is currently sitting on a github repository, with the first build pushed to heroku, although I'm not planning on publishing the url for the moment.