Class: CommentsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Blacklight::SolrHelper
Defined in:
app/controllers/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /comments POST /comments.xml



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/comments_controller.rb', line 61

def create
  @comment = Comment.new(params[:comment])
  @comment.user = current_user
  respond_to do |format|
    if @comment.save
      format.html { redirect_to(@comment) }
      format.xml  { render :xml => @comment, :status => :created, :location => @comment }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @comment.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /comments/1 DELETE /comments/1.xml



93
94
95
96
97
98
99
100
101
# File 'app/controllers/comments_controller.rb', line 93

def destroy
#  @comment = Comment.find(params[:id])
  @comment.destroy
  
  respond_to do |format|
    format.html {  redirect_to @comment }
    format.xml  { head :ok }
  end
end

#editObject

GET /comments/1/edit



54
55
56
57
# File 'app/controllers/comments_controller.rb', line 54

def edit
#  @comment = Comment.find(params[:id])

end

#indexObject

GET /comments GET /comments.xml



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/comments_controller.rb', line 12

def index
  if params[:catalog_id]
    @response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
    @document = @documents.first
  end

  @comments = @comments.where(:public => true) if params[:public]
  @comments = @comments.where(:commentable_id => @document.id, :commentable_type => @document.class.to_s) if @document
  @comments = @comments.where(:user_id => params[:user_id]) if params[:user_id]

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

#newObject

GET /comments/new GET /comments/new.xml



41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/comments_controller.rb', line 41

def new
  @response, @documents = get_solr_response_for_field_values("id",params[:catalog_id])
  @document = @documents.first

  @comment = Comment.new :commentable => @document

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

#showObject

GET /comments/1 GET /comments/1.xml



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

def show
 # @comment = Comment.find(params[:id])

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

#updateObject

PUT /comments/1 PUT /comments/1.xml



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/comments_controller.rb', line 77

def update
#  @comment = Comment.find(params[:id])

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