cirandas.net

ref: master

app/controllers/my_profile/circles_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class CirclesController < MyProfileController

  before_action :accept_only_post, :only => [:create, :update, :destroy]

  def index
    @circles = profile.circles
  end

  def new
    @circle = Circle.new
  end

  def create
    @circle = Circle.new(params[:circle].merge({ :person => profile }))
    if @circle.save
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
  end

  def xhr_create
    if request.xhr?
      circle = Circle.new(params[:circle].merge({:person => profile }))
      if circle.save
        render :partial => "circle_checkbox", :locals => { :circle => circle },
               :status => 201
      else
        render :text => _('The circle could not be saved'), :status => 400
      end
    else
      render_not_found
    end
  end

  def edit
    @circle = Circle.find_by_id(params[:id])
    render_not_found if @circle.nil?
  end

  def update
    @circle = Circle.find_by_id(params[:id])
    return render_not_found if @circle.nil?

    if @circle.update(params[:circle])
      redirect_to :action => 'index'
    else
      render :action => 'edit'
    end
  end

  def destroy
    @circle = Circle.find_by_id(params[:id])
    return render_not_found if @circle.nil?
    @circle.destroy
    redirect_to :action => 'index'
  end
end