Class ItemsController
In: app/controllers/items_controller.rb
Parent: ApplicationController

Methods

comment   country   create   flag   image   index   new   paginate   percent_order   share   show   tag  

Included Modules

Systems::Flickr

Public Instance methods

[Source]

     # File app/controllers/items_controller.rb, line 132
132:   def comment
133:     user = current_user
134:     user.update_attributes(:login => params[:user][:login]) if user.login.nil? || user.login.empty?
135:     params[:comment].merge!(:active => false) unless Param.boolean(Constants::Params::NO_MODERATE_COMMENTS)
136:     comment = Comment.new(params[:comment].merge(:visit_id => current_visit_id!))
137:     render :update do |page|
138:       if user.valid? && comment.save
139:         page[:login].html("<p>#{t('form.how_you_appear')}: <strong>#{current_user.login}</strong></p>") if params[:user] and params[:user][:login]
140:         comments = Comment.ordered_active(comment.item_id)
141:         notify(page, t('comment.success'))
142:         page[:comment_errors].html ''
143:         page[:comment_content].value = ''
144:         page[:comments_count].html comments.length
145:         page[:comments].html render(:partial => 'comment', :collection => comments)
146:       else
147:         error = user.valid? ? comment.errors.full_messages : "#{t('form.user_name')} #{user.errors.on('login')}"
148:         page[:comment_errors].html content_tag(:div, error, :class => 'errorExplanation')
149:       end
150:     end
151:   end

[Source]

     # File app/controllers/items_controller.rb, line 190
190:   def country
191:     session[:country_code] = params[:country_id].gsub(/\W/, '')[0,2].downcase
192:     questions =  Question.all
193:     fetch_stats(paginate_options, questions)
194:     render :update do |page|
195:       if @item_ids[params[:question_id].to_i].length < 1
196:         page[:flash_notice_content].html(t('items.not_enough_votes'))
197:         page.delay(1) { page[:flash_notice_content].fade(:duration => 1) }
198:       else
199:         @item_ids.each do |question_id, items|
200:           page["items_#{question_id}"].html(render(:partial => 'item', :collection => items, :locals => { :items => items, :question_id => question_id }))
201:           page[:flash_notice_content].fade(:duration => 1)
202:         end
203:       end
204:     end
205:   end

POST /items POST /items.xml can we do this asynchronously?

[Source]

     # File app/controllers/items_controller.rb, line 52
 52:   def create
 53:     @item_type = params[:item_type]
 54:     @item = Item.new(params[:item])
 55:     @question = params[:question][:id].to_i
 56:     if params[:item][:agree] == '1'
 57:       data = nil
 58:       case @item_type
 59:       when 'flickr'
 60:         if id = flickr?(params)
 61:           begin
 62:             @path, data = temp_file_for_flickr_id(id)
 63:             item, flickr = data_for_flickr_id(id)
 64:             if item && flickr
 65:               @item.external_link = item[:external_link]
 66:             else
 67:               @error = t('item.submit.flickr_fail')
 68:             end
 69:           rescue FlickRaw::FailedResponse
 70:             @error = t('item.submit.flickr_fail')
 71:           end
 72:         end
 73:         data || @error = t('item.submit.fail.flickr')
 74:       when 'url'
 75:         url = params[:url]
 76:         if !(url.empty? || detect_content_type(url).nil?)
 77:           @path, data = temp_file_for_url(url)
 78:           @item.external_link = url
 79:         end
 80:         data || @error = t('item.submit.fail.url')
 81:       end
 82:       @attachment = data ? Attachment.new(:uploaded_data => data) : Attachment.new(params[:attachment])
 83:       if Item.valid_objects(@item, @attachment, [@question])
 84:         item = Item.new_remote(@item, @attachment, [@question], current_visit_id!)
 85:         # create stat for the item
 86:         for group in Group.all
 87:           Stat.create(
 88:             :item_id => item.id,
 89:             :question_id => @question,
 90:             :group_id => group.id,
 91:             :ratings => 0,
 92:             :wins => 0,
 93:             :losses => 0
 94:           )
 95:         end
 96:         if flickr?(params) && item
 97:           Flickr.create(flickr.merge(:item_id => item.id))
 98:         end
 99:         File.delete(@path) if @path
100:         @item = Item.new
101:         @create = flash.now[:notice] = t("item.create")
102:       end
103:     end
104:     if flash[:notice].nil?
105:       @item.errors.add('id', @error || t('item.submit.fail.upload'))
106:       flash.now[:error] = t('item.submit.fail.h')
107:     end
108:     fetch_user_items
109:     render :action => 'new'
110:   ensure
111:     GC.start # cleanup memory
112:   end

[Source]

     # File app/controllers/items_controller.rb, line 114
114:   def flag
115:     unless (flag = flag_obj(params[:flag])).new_record?
116:       flash.now[:notice] = flag.item_id ? t('item.flag.success') : t('comment.flag.success')
117:       if flag.item_id
118:         redirect_to items_path
119:       else
120:         redirect_to item_path(flag.comment.item_id)
121:       end
122:     else
123:       @item = Item.find(params[:flag][:item_id], :conditions => { :active => true })
124:       @flag = flag
125:       render :action => 'show'
126:     end
127:   rescue ActiveRecord::RecordNotFound
128:     redirect_to items_path
129:     return
130:   end

[Source]

    # File app/controllers/items_controller.rb, line 23
23:   def image
24:     @attachment = Item.find(params[:id]).attachment
25:     send_data(@attachment.public_filename(:compare), :type => @attachment.content_type, :disposition => 'attachment')
26:   end

GET /items GET /items.xml

[Source]

    # File app/controllers/items_controller.rb, line 16
16:   def index
17:     @active_question_id = current_question.id
18:     @questions = Question.all
19:     fetch_stats(paginate_options, @questions)
20:     fetch_user_items
21:   end

GET /items/new GET /items/new.xml

[Source]

    # File app/controllers/items_controller.rb, line 42
42:   def new
43:     @item = Item.new
44:     @item_type = 'upload'
45:     @questions = [current_question.id]
46:     fetch_user_items
47:   end

[Source]

     # File app/controllers/items_controller.rb, line 180
180:   def paginate
181:     question = Question.find(params[:id])
182:     @active_question_id = question.id
183:     fetch_stats(paginate_options, [question])
184:     render :update do |page|
185:       page["items_#{@active_question_id}"].html render(:partial => 'item', :collection => @item_ids[question.id], :locals => { :question_id => question.id })
186:       page << "window.scrollTo(0,0);"
187:     end
188:   end

[Source]

     # File app/controllers/items_controller.rb, line 207
207:   def percent_order; '(items_questions.wins/items_questions.ratings) desc' end

[Source]

     # File app/controllers/items_controller.rb, line 164
164:   def share
165:     @mailing = Mailing.new(setup_mail_params(params[:mailing]))
166:     render :update do |page|
167:       if @mailing.save
168:         page[:mailing_name].value = ''
169:         page[:mailing_email].value = ''
170:         page[:mailing_message].value = ''
171:         page[:mailing].hide
172:         notify(page, t('item.send.success'))
173:       else
174:         page[:mailing_errors].html error_messages_for('mailing')
175:       end
176:     end
177:     @mailing.send_item unless @mailing.new_record?
178:   end

GET /items/1 GET /items/1.xml

[Source]

    # File app/controllers/items_controller.rb, line 30
30:   def show
31:     @current_user = current_user
32:     conditions = @admin_user ? {} : { :conditions => { :active => true } }
33:     @item = Item.find(params[:id], conditions)
34:     @groups = Group.all(:select => 'code, name, id')
35:   rescue ActiveRecord::RecordNotFound
36:     redirect_to items_path
37:     return
38:   end

[Source]

     # File app/controllers/items_controller.rb, line 153
153:   def tag
154:     @item = Item.find(params[:tag][:item_id])
155:     context = Question.find(params[:tag][:question_id], :include => :groups).groups.first.code.to_sym
156:     @item.set_tag_list_on(context, "#{@item.tag_list_on(context)},#{params[:tag][:content]}")
157:     @item.save
158:     @item = @item.reload
159:     render :update do |page|
160:       page[:tags].html render(:partial => 'tags')
161:     end
162:   end

[Validate]