Class: SuggestionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/suggestions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#createObject

POST /suggestions POST /suggestions.xml



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/suggestions_controller.rb', line 47

def create
  @suggestion = Suggestion.new(params[:suggestion])
  @suggestion.user_id = current_user.id if current_user
  page = @suggestion.page


  respond_to do |format|
    if @suggestion.save
      flash[:notice] = 'Thank you for your suggestion'
      format.html { redirect_to @suggestion.page }
      format.xml { render :xml => @suggestion, :status => :created, :location => @suggestion }
    else
      format.html { render :action => "new" }
      format.xml { render :xml => @suggestion.errors, :status => :unprocessable_entity }
    end
  end

  email_suggestion(@suggestion, "created")
end

#destroyObject

DELETE /suggestions/1 DELETE /suggestions/1.xml



88
89
90
91
92
93
94
95
96
# File 'app/controllers/suggestions_controller.rb', line 88

def destroy
  @suggestion = Suggestion.find(params[:id])
  @suggestion.destroy

  respond_to do |format|
    format.html { redirect_to(suggestions_url) }
    format.xml { head :ok }
  end
end

#editObject

GET /suggestions/1/edit



40
41
42
43
# File 'app/controllers/suggestions_controller.rb', line 40

def edit
  @suggestion = Suggestion.find(params[:id])

end

#email_suggestion(suggestion, status) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/suggestions_controller.rb', line 99

def email_suggestion(suggestion, status)

  message = "\"#{suggestion.comment}\"<br/><br/>"
  message = message + "by #{suggestion.user.human_name}" unless suggestion.user.nil?

  options = {:to => "[email protected]",
             :subject => "Suggestion #{status}",
             :message => message,
             :url_label => "Show this suggestion",
             :url => "http://whiteboard.sv.cmu.edu" + suggestion_path(suggestion)
  }
  GenericMailer.email(options).deliver

end

#indexObject

GET /suggestions GET /suggestions.xml



7
8
9
10
11
12
13
14
# File 'app/controllers/suggestions_controller.rb', line 7

def index
  @suggestions = Suggestion.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @suggestions }
  end
end

#newObject

GET /suggestions/new GET /suggestions/new.xml



29
30
31
32
33
34
35
36
37
# File 'app/controllers/suggestions_controller.rb', line 29

def new
  @suggestion = Suggestion.new
  @suggestion.page = request.env["HTTP_REFERER"]

  respond_to do |format|
    format.html # new.html.erb
    format.xml { render :xml => @suggestion }
  end
end

#showObject

GET /suggestions/1 GET /suggestions/1.xml



18
19
20
21
22
23
24
25
# File 'app/controllers/suggestions_controller.rb', line 18

def show
  @suggestion = Suggestion.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml { render :xml => @suggestion }
  end
end

#updateObject

PUT /suggestions/1 PUT /suggestions/1.xml



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/suggestions_controller.rb', line 69

def update
  @suggestion = Suggestion.find(params[:id])

  respond_to do |format|
    if @suggestion.update_attributes(params[:suggestion])
      flash[:notice] = 'suggestion was successfully updated.'
      format.html { redirect_to(@suggestion) }
      format.xml { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml { render :xml => @suggestion.errors, :status => :unprocessable_entity }
    end
  end

  email_suggestion(@suggestion, "updated")
end