Skip to content
parolkar edited this page Mar 4, 2011 · 5 revisions

Here is an example of how you can make use of the plugin

Whats required?

  1. Your app with models which require profiles to be attached to them
  2. You are OK with installing haml/sass in your app & your app is on rails 2.3+

Here you go!

  • Let me quickly help you in building an app from scratch (if you dont have one yet)

    $ rails your_app $ cd your_app $ git init $ ruby script/generate model User nickname:string password:string $ ruby script/generate model Company shortname:string $ ruby script/generate controller Profile index
  • You need to install compass (for haml/sass) in you app , check the instructions here and then setup the plugin

    $ git submodule add git://github.com/parolkar/has_profile_items.git vendor/plugins/has_profile_items $ rake has_profile_items:setup
  • and then just make use of has_profile_items

class User < ActiveRecord::Base
has_profile_items [:first_name]  # Add has_profile_items [:item_type1,:item_type2,…]
end

class Company < ActiveRecord::Base
has_profile_items [:description]
end
class ProfileController < ApplicationController
def index
user = User.find_or_create_by_nickname(params[:id]) # for you, this can be ‘current_user’
@profile_items = user.profile_item_list
end
end

  • add this is views/profile/index.html.erb
 
   Welcome to your profile
    <%= render :partial => 'profile_items/profile_item', :collection =>  @profile_items -%>

  • Run script/server & point your browser to http://localhost:3000/profile/index/yournick
Clone this wiki locally