Oooh man, it’s been an exciting weekend. Alongside the effort and work in packing up the house to move shortly I’ve been spending a heap of downtime reading, practicing and learning about functional programming. I’d like to give a massive thanks to Becoming Functional by Joshua Backfield, it’s an easy to digest, fun to read text which follows the evolution of a fictional use-case/company as you rewrite it’s imperative code as functional.
My apologies for the absence and lack of updates although this may be closer to regular schedule in the future, depending on how circumstances turn out (vague-/personal-posting, sorry), but I have been working on some projects. In particular, my main focus has been on a commercial shopping cart website for a friend that I’m developing. I can’t give too much information about it since the project is still underway but it involves building my own shopping cart, creating a content management system for my friend to simply log in and update content, etc.
Alright, so with the blog and forum components slowly shaping up I thought I’d try my hand at putting together a chat client for the SiteHub project. I don’t know if I’ll be building tutorials for this one, most of the groundwork is covered pretty well by the RailsCast crew here and if you’ve followed my other tutorials you will probably be able to get most of the features done easily without my instruction.
Continuing on from Part 2 of our Rails Blog tutorial, now we’re going to be adding in a tag system so users can tag posts and check out what posts are available under a particular tag.
To start with, run rails g model Tag name:string to generate a model for the tags then run rails g migration posts_tags and find the migration this generated (typically db/migrate/YYYYMMDDHHMMSS_create_tags.rb with a different time stamp) and add the following inside the change method:
By now you should have a blog with users, administrators and even a tag system as of part 3 in this series, so now we’re onto something for greater aesthetics. In this case, custom URLs for posts and tags.
We’ll start by running rails g migration add_url_to_tags_and_users, this generates a migration that we can open up (usually in db/migrate/YYYYMMDDHHMMSS_add_url_to_tags_and_users.rb) and add the following inside the change method:
add_column :tags, :url, :string add_column :posts, :url, :string This will add columns for the url component to both the Tag and Post model and we can send these changes to the database with rake db:migrate.
This is a continuation of the SiteHub project brought up in my Rails Forum Skeleton tutorials (Part 1, Part 2, Part 3, Thoughts), moving on to developing the news-site/blog component that the project will hopefully involve. If you’ve been through those tutorials you’ll likely see some familiar commands and actions, however I’ll do my best to explain everything for newcomers as well.
Firstly, I’ll be using Ruby 2.1.1 or greater and Rails 4.
Continuing on from the first part of the Rails Blog tutorial we’re going to flesh out our blog concept even further. Now we want to create an administrator role who has permissions to edit/delete other’s posts in case they contain unsuitable material or are outdated and the connected account is deleted. There’s a few possible ways of doing this, but what we’re going to do is add a boolean attribute to the user model that signifies whether a user is an administrator.
Following on from my last tutorial where we set up users and primitive authentication/access control, we’re going to work on fleshing out the forum aspect further. Let’s start by allowing login and identifying users by a separate value, a “username”.
I’ve added username as an attribute to the User model, to do that run rails g migration AddUsernameToUsers username:string then enter rake db:migrate. To get it working as the identifier for accounts you’ll need to go to config/initializers/devise.
With the three tutorials done so far (Part 1, Part 2, Part 3) I’m thinking about letting this series rest. By the time you reach this level, you should hopefully be ready to spread your own wings and begin adding the features you want on your own. If you’re still stuck about how to implement an idea you have, feel free to hit me up at @adamjogrady or one of my other contact methods and I can look into it with you.
Here’s a quick tutorial on how to create a framework for a forum. It doesn’t get into creating users, authentication or permissions, it’s mostly to show the relationships between entities and shore up the right views.
Preface: So in the quest for new projects I’ve considered building an all-in-one website-forum-chatroom package with the goal of creating something that people can download to their server, run an install script and it sets up everything necessary and then allows the user to do post-install customisation (setting up static website pages, creating user permission levels, forum headings, etc).