Class: Suggestion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Suggestion
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/models/suggestion.rb
Class Method Summary collapse
- .chronological ⇒ Object
- .create_suggestion(ip, params) ⇒ Object
- .hidden ⇒ Object
- .reverse_chronological ⇒ Object
- .search(query) ⇒ Object
- .shown ⇒ Object
- .toggle!(params) ⇒ Object
Instance Method Summary collapse
- #description ⇒ Object
- #formatted_created_at ⇒ Object
- #hidden? ⇒ Boolean
- #search_url ⇒ Object
- #shown? ⇒ Boolean
- #toggle! ⇒ Object
- #truncated_content ⇒ Object
Class Method Details
.chronological ⇒ Object
59 60 61 |
# File 'app/models/suggestion.rb', line 59 def chronological order "created_at ASC" end |
.create_suggestion(ip, params) ⇒ Object
46 47 48 49 |
# File 'app/models/suggestion.rb', line 46 def create_suggestion(ip, params) return nil unless params[:content].present? create :name => params[:name], :email => params[:email], :ip => ip, :content => params[:content] end |
.hidden ⇒ Object
51 52 53 |
# File 'app/models/suggestion.rb', line 51 def hidden where :hidden => true end |
.reverse_chronological ⇒ Object
63 64 65 |
# File 'app/models/suggestion.rb', line 63 def reverse_chronological order "created_at DESC" end |
.search(query) ⇒ Object
34 35 36 |
# File 'app/models/suggestion.rb', line 34 def search(query) reverse_chronological.shown.where "LOWER(name) LIKE :query OR LOWER(email) LIKE :query OR LOWER(ip) LIKE :query OR LOWER(content) LIKE :query", :query => "%#{query.downcase}%" end |
.shown ⇒ Object
55 56 57 |
# File 'app/models/suggestion.rb', line 55 def shown where :hidden => false end |
.toggle!(params) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/models/suggestion.rb', line 38 def toggle!(params) if params[:id].present? find(params[:id].to_i).toggle! elsif params[:ids].present? where(:id => params[:ids].map(&:to_i)).each &:toggle! end end |
Instance Method Details
#description ⇒ Object
25 26 27 |
# File 'app/models/suggestion.rb', line 25 def description "#{I18n.t "suggestion"}: #{truncated_content}" end |
#formatted_created_at ⇒ Object
4 5 6 |
# File 'app/models/suggestion.rb', line 4 def formatted_created_at created_at.localtime.strftime "%-m/%-d/%Y at %-l:%M %P" end |
#hidden? ⇒ Boolean
12 13 14 |
# File 'app/models/suggestion.rb', line 12 def hidden? hidden end |
#search_url ⇒ Object
29 30 31 |
# File 'app/models/suggestion.rb', line 29 def search_url "/admin/suggestions/#{id}" end |
#shown? ⇒ Boolean
8 9 10 |
# File 'app/models/suggestion.rb', line 8 def shown? !hidden end |
#toggle! ⇒ Object
16 17 18 19 |
# File 'app/models/suggestion.rb', line 16 def toggle! self.hidden = !hidden save! end |
#truncated_content ⇒ Object
21 22 23 |
# File 'app/models/suggestion.rb', line 21 def truncated_content truncate content, :length => 256 end |