Class: Muck::ProfilesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/profiles_controller.rb

Instance Method Summary collapse

Instance Method Details

#editObject

Renders an edit for for the current user’s profile

It is simple to override the edit template. Simply create a template in app/views/profiles/edit.html.erb and add something similar to the following:

<div id="edit_profile">
  <%= output_errors(t('muck.profiles.problem_editing_profile'), {:class => 'help-box'}, @profile) %>
  <%= profile_form(@user) do |f| -%>
    <%# Add custom fields here.  ie %>
    <%= f.text_field :custom_thing %>
  <% end -%>
</div>


57
58
59
60
61
62
63
64
# File 'app/controllers/muck/profiles_controller.rb', line 57

def edit
  @profile = @user.profile
  @page_title = t('muck.profiles.edit_profile_title', :name => @user.display_name)
  respond_to do |format|
    format.pjs { render :template => 'profiles/edit', :layout => false } # fancybox request 
    format.html { render :template => 'profiles/edit' }
  end
end

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/muck/profiles_controller.rb', line 5

def index
  @per_page = 400
  @users = User.by_newest.paginate(:page => @page, :per_page => @per_page, :include => 'profile')
  respond_to do |format|
    format.html { render :template => 'profiles/index' }
  end
end

#searchObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/muck/profiles_controller.rb', line 13

def search
  @query = params[:q]
  @page = (params[:page] || 1).to_i
  @rows = (params[:rows] || 10).to_i
  if MuckProfile.configuration.enable_solr
    results = Profile.find_by_solr(@query, :limit => @rows, :offset => @rows*(@page-1), :core => 'en')
    @hit_count = results.total
    @users = results.results.paginate(:page => @page, :per_page => @rows, :total_entries => @hit_count)
  elsif MuckProfile.configuration.enable_sunspot
    results = Sunspot.search Profile do
      keywords @query
      paginate :page => @page, :per_page => @per_page
    end      
    @hit_count = results.total
    @users = results.results.paginate(:page => @page, :per_page => @rows, :total_entries => @hit_count)
  else
    raise translate('muck.profiles.search_not_enabled')
  end
  
  respond_to do |format|
    format.html { render :template => 'profiles/index' }
  end
end

#showObject

show a given user’s public profile information



38
39
40
41
42
43
44
# File 'app/controllers/muck/profiles_controller.rb', line 38

def show
  @profile = @user.profile
  @page_title = @user.display_name
  respond_to do |format|
    format.html { render :template => 'profiles/show' }
  end
end

#updateObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/muck/profiles_controller.rb', line 66

def update
  @user = User.find(params[:user_id])
  @profile = @user.profile
  @page_title = t('muck.profiles.edit_profile_title', :name => @user.display_name)
  @user.update_attributes!(params[:user])
  respond_to do |format|
    flash[:notice] = t('muck.profiles.edit_success')
    format.html { redirect_back_or_default (@user) }
  end
rescue ActiveRecord::RecordInvalid => ex
  flash[:error] = t('muck.profiles.edit_failure')
  render :action => :edit
end