Class | DocumentsController
In: | app/controllers/documents_controller.rb
Parent: | ApplicationController

### Methods

email image index photo send_email show vote

### Public Instance methods

email()

[Source]

        # File app/controllers/documents_controller.rb, line 85
    85:   def email
    86:     @document = Document.find(params[:id])
    87:
    88:   end

image()

[Source]

        # File app/controllers/documents_controller.rb, line 75
    75:   def image
    76:     file_to_send = get_or_generate_desired_image(params[:path], params[:size])
    77:     send_file(file_to_send, :type => 'image/jpeg', :disposition => 'inline')
    78:   end

index()

This controller is used only for News. Other document types, has their own controllers.

[Source]

        # File app/controllers/documents_controller.rb, line 8
     8:   def index
     9:     @title = t('documents.News')
    10:     @documents = News.in_irekia.published.translated.paginate :page => params[:page], :per_page => 15, :order => 'published_at DESC'
    11:     respond_to do |format|
    12:       format.html
    13:       format.rss {render :layout => false}
    14:     end
    15:   end

photo()

[Source]

        # File app/controllers/documents_controller.rb, line 80
    80:   def photo
    81:     @file_to_send = params[:path]
    82:     render :action => 'photo', :layout => false
    83:   end

send_email()

[Source]

         # File app/controllers/documents_controller.rb, line 90
     90:   def send_email
     91:     @document = Document.find(params[:id])
     92:     if params[:sender_name].blank? || params[:recipient_name].blank? || params[:recipient_email].blank?
     93:       flash[:error] = t('share.todos_campos')
     94:       render :action => "email" and return
     95:     elsif !params[:recipient_email].match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
     96:       flash[:error] = t('share.email_incorrecto')
     97:       render :action => "email" and return
     98:     end
     99:
    100:     email = Notifier.create_email_document(params[:sender_name], params[:recipient_name], params[:recipient_email], @document)
    101:
    102:     begin
    103:       logger.info("Mandando documento")
    104:       Notifier.deliver(email)
    105:       flash[:notice] =  t('share.pagina_enviada')
    106:     rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
    107:       logger.info("Error al mandar mail de pagina: " + err_type)
    108:       flash[:error] = t('session.Error_servidor_correo')
    109:     end
    110:
    111:     redirect_to @document
    112:   end

show()

[Source]

        # File app/controllers/documents_controller.rb, line 17
    17:   def show
    18:     begin
    19:       @document = News.in_irekia.published.find(params[:id])
    20:     rescue ActiveRecord::RecordNotFound
    21:       if can_edit?("news")
    22:         @document = News.in_irekia.find(params[:id])
    23:       else
    24:         raise ActiveRecord::RecordNotFound
    25:       end
    26:     end
    27:
    28:     @parent = @document
    29:     @comments = @document.comments.approved.paginate :page => params[:page], :per_page => 50
    30:
    31:     respond_to do |format|
    32:       format.html {
    33:         render
    34:       }
    35:       format.iphone {
    36:         render :layout => false
    37:       }
    38:     end
    39:
    40:   end

vote()

[Source]

        # File app/controllers/documents_controller.rb, line 42
    42:   def vote
    43:     @document = News.published.in_irekia.find(params[:id])
    44:
    45:     @document.ratings.build(:rating => params[:vote].to_i)
    46:
    47:     if @document.save
    48:       cookies["vote_#{@document.id}"] = {:value => params[:vote], :expires => 1.month.from_now}
    49:       respond_to do |format|
    50:         format.html {
    51:           flash[:notice] = "Gracias por tu voto"
    52:           redirect_to @document
    53:         }
    54:         format.js {
    55:           render :update do |page|
    56:             page.replace :vote_action, :partial => "voted", :locals => {:vote => params[:vote].to_i}
    57:             page<<"$('current_rating').setStyle({width: '#{(@document.ratings.average('rating')/5.0*100).to_i}%'})"
    58:           end
    59:         }
    60:       end
    61:     else
    62:       respond_to do |format|
    63:         format.html {
    64:           flash[:error] = "Tu voto no se ha guardado. Por favor, inténtalo más tarde"
    65:           redirect_to @document
    66:         }
    67:         format.js {
    68:           logger.info "El voto no se ha guardado: #{@document.errors.inspect}"
    69:           render :nothing => true
    70:         }
    71:       end
    72:     end
    73:   end

[Validate]