Tech Stuff

Rails controller namespaces

Mainly used if you have actions on the same controller that deals with “admin” and “non-admin” users. This eliminates the need to put a lot of redundant checking on actions just to differentiate from these roles. And also, it’s a nice way to organize your codes.

map.namespace :admin do |admin|
   admin.resources :posts
class Admin::PostsController < ApplicationController
    before_filter :assert_if_admin
    # some code. . .
    def assert_if_admin
      unless current_user.is_admin?
        redirect_to root_path

and that’s it! just change the routes of your links to point to specific actions on the namespaced controller :)

also, if you have form_for @post added in your code, you can change it to use the namespaced route to: form_for [:admin, @post], this will generate a path /admin/posts/ to your form



Random Stuff, Tech Stuff

Website in 1 week, wtf!

And this is not some ordinary site, a sort-of social networking site!

Until now I still can’t believe my friend and I took the project. You can’t create a site in one week?! Maybe a personal site (weebly FTW), but not a social networking site. I mean the logic and DB alone will take days or so to plan, and not to mention the design and stuff, AND we both have a job too.

This is going to be the busiest week of my entire life. If we ever going to make it and get that site running in a week, that would be the biggest and so far the proudest accomplishment I’ve ever made in my programming life. (Wow, I just have my motivation in this project. haha) Something that I can be proud of for the rest of my life.

This is going to be a one hell of a project. Hope we’re gonna make it!

‘Nuff blogging. Let’s get this possimpible project started. Oh Rails, help me get through with it :D