Class: DescriptionsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user, #current_user Used for unit testing, this is normally managed by Devise

Instance Method Summary collapse

Methods inherited from ApplicationController

#clear_search_index

Instance Method Details

#bulkObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/descriptions_controller.rb', line 97

def bulk
  descriptions = descriptions_params[:descriptions]

  success_count = 0
  fail_count = 0
  errors = ""

  descriptions.each do |k, a|
    puts a
    if Description.find(a[:id]).update(status_id: a[:status_id])
      success_count += 1
    else
      fail_count += 1
    end
  end

  if fail_count == 0 and success_count > 0
    flash[:success] = success_count.to_s + " descriptions updated."
  elsif fail_count == 0 and success_count == 0
    flash[:notice] = "No descriptions updated."
  else
    error = fail_count.to_s + " descriptions failed.  " + errors  
    if success_count > 0 
      error +=  success_count.to_s + " descriptions updated."
    end
    flash[:error]  = error
  end
  render nothing: true
end

#createObject



75
76
77
78
79
# File 'app/controllers/descriptions_controller.rb', line 75

def create
  @description = Description.new(description_params)
  flash[:notice] = "#{@description} was successfully created." if @description.save
  respond_with(@description)
end

#destroyObject



91
92
93
94
95
# File 'app/controllers/descriptions_controller.rb', line 91

def destroy
  @description.destroy
  flash[:notice] = "Description was successfully destroyed."
  respond_with(@description)
end

#editObject

GET /descriptions/1/edit



68
69
70
# File 'app/controllers/descriptions_controller.rb', line 68

def edit
  @siblings = @description.image.descriptions
end

#indexObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/descriptions_controller.rb', line 35

def index
  if request.format.html? and current_user
    @search_cache_key = search_params
    if search_params
      search_params["text_cont_all"] = search_params["text_cont_all"].split(" ")  if search_params["text_cont_all"]
    end
    @q = Description.ransack(search_params)
    @descriptions = @q.result(distinct: true).page(params[:page]) 
  else
    @descriptions = Description.all.page params[:page]
  end
end

#newObject

GET /descriptions/new



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/descriptions_controller.rb', line 54

def new
  @description = Description.new
  if params[:user_id] 
    @author = User.find(params[:user_id])
  else
    @author = current_user
  end
  if @image
    @description.image = @image
    @siblings = @description.image.descriptions
  end
end

#showObject



50
51
# File 'app/controllers/descriptions_controller.rb', line 50

def show
end

#updateObject



84
85
86
87
# File 'app/controllers/descriptions_controller.rb', line 84

def update
  flash[:notice] = "#{@description} was successfully updated." if @description.update(description_params)
  respond_with @description
end