Skip to content
Photo Blog built with Ruby on Rails
Ruby HTML CSS JavaScript CoffeeScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
lib
log
public
spec
test
tmp
vendor/assets
.gitignore
.rspec
.ruby-version
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru
wizard.jpg

README.md

Photo Blog

A photo blog to keep track of interesting photos and experiences. This is my current project as a delve into learning Rails, so additional features will be added as I explore all the things I can do with Ruby on Rails.

https://foodforthesoul-blog.herokuapp.com/

Updated - now responsive for small screens/mobiles

Environment

Originally built and tested in Windows 10 Home. Currently it's being transferred to development on a Mac, so some of the files and settings have been changed to run on OSX rather than Windows.

System Dependencies & Configuration

Built with

  • Ruby version: 2.5.0
  • Rails version: 5.0.7.2
  • Bundler version: 2.0.1 (as Heroku is still using Bundler version 1.15.2, run this command before pushing up to heroku heroku buildpacks:set https://github.com/bundler/heroku-buildpack-bundler2)

Downloaded via the RailsInstaller [http://railsinstaller.org/en]. This includes DevKit which is necessary for a Windows environment (e.g. for paperclip gem)

See the discussion section below for additional information about the creation of this app.

Operating Instructions

The Blog is on Heroku - Food for the Soul

Users can

  • view entries by everyone
  • register for their own account (and pick a colour for their post header)
  • log in

Users who are logged in can also

  • view a list of their own blog posts
  • edit and delete their own blog posts

The app is currently populated with seed data (users and blog entries). You can create your own account or use an existing one (username: ab@gmail.com ; password: foobar - you can work out the usernames from this)

Testing Instructions

Totally a work in progress as I am still learning how to do TDD and testing in general

Run server locally

To run the server locally

rails s

Instructions from the Rspec README

To run the specs:

bundle exec rspec

or

rspec

To run only a subset of these specs use the following command:

# Run only feature specs (all specs are currently here)
bundle exec rspec ./spec/features

# Run only specs for deleting posts
bundle exec rspec ./spec/features/deleting_posts_spec.rb

# Run only spec on line 16 of AccountsController
bundle exec rspec ./spec/features/deleting_posts_spec.rb:16

Overview

The idea of this photo blog was to build something using Ruby on Rails that I would continue to use and improve upon. I wanted to learn how to use Rails so this project came about. At it's most basic, it's a platform for me to share photos and thoughts. But I'll be adding features over time as I explore all the different features in Rails.

Currently users can pick a color to differentiate themselves from other users.

The fields for each post include

  • Image: the photo
  • Caption: a short description
  • Location: where the photo was taken
  • Blog: thoughts, discussions, opinions, ramblings

Discussion and Lessons Learnt

Below is a reflection around the setup and any challenges I exerienced in building this rails app, gemfiles added and nitty gritty frustrations and helpful resources.

Some of the problems and solutions are still rather obscure and I plan to do further research into why errors occur and why those solutions work.

Gemfile

update excluding the production gems

$ bundle install --without production

Gems added:

bundle initially was not working when running in the Visual Studio Code terminal (it was working using git bash). The problem was that the path could not be located. Following a suggestion on the web, I replaced the code in C:\RailsInstaller\Ruby2.3.0\bin\bundle.bat to

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
GOTO :EOF
:WinNT
@"%~dp0ruby.exe" "%~dpn0" %*

I also ran into issues with bcrypt which wouldn't load (it is used by devise). This was due to the version of bcrypt that was installed. Devise installed

$gem list bcrypt
bcrypt (3.1.11 x86-mingw32)

Solved by making sure the bcrypt version is just bcrypt (3.1.11)

gem uninstall devise && gem uninstall bcrypt
gem install bcrypt --platform=ruby
Added gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt' and bundle install

Database

I encountered problems with dropping/resetting the development database table which threw the following error

Couldn't drop database 'db/development.sqlite3'
rails aborted!
Errno::EACCES: Permission denied @ unlink_internal - ................./development.sqlite3
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)

In order to reset the table run

$ rails db:drop:_unsafe
$ rails db:create
$ rails db:migrate
$ rails db:seed

Heroku

Instructions on Heroku to set up Paperclip and AWS S3 for storage

Some commands for pushing to production on Heroku

$ git push heroku master
$ heroku pg:reset DATABASE
$ heroku run rails db:migrate
$ heroku run rails db:seed
$ heroku restart

To uncompile/precompile assets if required (shouldn't be for rails 5)

$RAILS_ENV=development rails assets:clobber
$ bundle exec rails assets:precompile

Capybara

A useful cheatsheet/guide

Random

I ran into a peculiar issue where buttons stopped working in Firefox but did work in Chrome and IE. Links were fine, just not when they were in buttons. I finally tracked the problem down to using link_to inside <button>. Resolved by adding class='btn btn-<whatever>' to the link_to instead. This was odd because buttons had been working but I believe changing the order in application.js may have caused this issue whilst fixing other issues. The order of the entries in application.js is important.

You can’t perform that action at this time.