3

I have a rails 3 devise app has users with a profile and privacy settings. I currently have this working, but am concerned about efficiency and would love the advice of an experienced rails dev.

I generated User model with devise and scaffolded out Profile and Privacy models to contain items deemed not required for sign up. I would like the the User to have different settings links.

Account Settings => Devise - just required login type stuff, username, password Profile Settings => Profile model - description, avatar, birthday etc. Privacy Settings => Privacy model - checkboxes that control basic hiding/showing of the user's profile fields.

I have set up my relationships:

user.rb

has_one :profile
has_one :privacy

profile.rb

belongs_to :user

privacy.rb

belongs_to :user

This seems horribly inefficient to me. To display the profile I am relying on loading three tables: users, profiles, and privacies.

I think that all of the table columns from Profile and Privacy should be contained in the users table, would this make more sense? How would I separate the different forms?

My one thought was to just add a profile method and a privacy method to the users controller, than I could make profile and privacy templates in my users views. with different forms controlling the different portions of the user record that each would edit.

Does this make sense? Would this make more sense than separate scaffolds like I currently have?

Thomas
  • 2,426
  • 3
  • 23
  • 38

1 Answers1

5

I think you're doing it in a very difficult way. To add a User Profile Page just

$ rails generate controller Users show

in your app/controllers/users_controller.rb

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
  end
end  

in your app/views/users/show.html.erb

<h1><%= @user.name %></h1>

and then just add w/e you want to the Profile Page.

in your config/routes.rb

devise_for :users
get 'users/:id' => 'users#show', as: :user

Hope this Helps with the User Profile

Mini John
  • 7,855
  • 9
  • 59
  • 108