=begin rdoc
	iCookWare Setting controller class:: represents user settings stored in the database
	Author:: Ana Kovatcheva. 2005
	© Copyright:: iCookWare Team 2005  
=end

class SettingsController < ApplicationController
  before_filter :login_required

	layout  'icw'
  def index
    #list
    render_action 'show'
  end

	#listing all settings (of all users) should go into an admin view. still here for debugging!
  def list_all			
    @setting_pages, @settings = paginate :setting, :per_page => 10
  end

	#show only the own user settings
  def show
    @setting = @session[:user].setting
  end

#def new
#	@settings=Setting.new
#end

def edit
	if @session[:user]
		@setting = @session[:user].setting
	else
     redirect_to :controller => 'account' , :action => 'login'
  end
end


	#we should check if the user updates the right settings


  def update
    @setting = Setting.find(@params[:id])
		
    if @setting.update_attributes(@params[:setting])
      flash['notice'] = 'Setting was successfully updated.'
      redirect_to :action => 'show', :id => @setting
    else
      render_action 'edit'
    end
  end

end
