Francisco Quinones

Joined

7,400 Experience
40 Lessons Completed
2 Questions Solved

Activity

I found that this works

<%= link_to Report, project_incidents_path(params.merge(format: "pdf")), :class=> "btn" %>

I get this

http://companydemo.lvh.me:3000/projects/conroy-schamberger-and-crooks/incidents?action=index&commit=Buscar&controller=incidents&format=pdf&from_date=01%2F01%2F2016&project_id=conroy-schamberger-and-crooks&to_date=31%2F01%2F2016&utf8=%E2%9C%93

but I dont know if is the best way.

So Chris im using prawn pdf in my app.
Now im adding some search form to filter by date range. All works fine and I get my filter table on my index. my problem is with prawn that wont hold the filter records

my form filter range

        <%= form_tag({controller: "accidents", action: "index"}, {:class => 'navbar-form navbar-left', method: "get"}) do %>
              <%= text_field_tag :from_date, params[:from_date], class: "form-control", placeholder: "Fecha Inicial" %>
              <%= text_field_tag :to_date, params[:to_date], class: "form-control", placeholder: "Fecha Final" %>
              <%= submit_tag 'Buscar', class: "btn btn-primary" %>
        <% end %>

my controller code

  def index
    if params[:from_date] && params[:to_date].present?
       from_date = Date.strptime(params[:from_date], "%d/%m/%Y")
       to_date = Date.strptime(params[:to_date], "%d/%m/%Y") + 1.day
       @accidents = @project.accidents.sorting.where(:date => from_date..to_date)
       .paginate(:page => params[:accidents], :per_page => 10)
    else
        @accidents = @project.accidents.sorting.paginate(:page => params[:accidents], :per_page => 10)
    end
    respond_to do |format|
        format.html
        # format.csv { send_data  @accidents.to_csv}
        format.pdf do
          pdf = AccidentsReportPdf.new(@accidents,@project)
          send_data pdf.render,filename: "accidente_reporte_#{@project.name}.pdf",
                              type: "application/pdf",
                              disposition: "inline"
      end
    end
  end

This my index filter with a range of date

http://companydemo.lvh.me:3000/projects/conroy-schamberger-and-crooks/accidents?utf8=%E2%9C%93&from_date=01%2F01%2F2016&to_date=31%2F01%2F2016&commit=Buscar

when I go to see the pdf version

<%= link_to Report, project_incidents_path(format: "pdf"), :class=> "btn" %>

I get

  http://companydemo.lvh.me:3000/projects/conroy-schamberger-and-crooks/accidents.pdf

maybe I need to past the dates to the link_to pdf. If so how is the right way to pass that data.

@chris on my sideq im getting this error any idea??

09:37:22 redis_s.1 | 33693:M 07 Dec 09:37:22.096 * 100 changes in 300 seconds. Saving...
09:37:22 redis_s.1 | 33693:M 07 Dec 09:37:22.097 * Background saving started by pid 71671
09:37:22 redis_s.1 | 71671:C 07 Dec 09:37:22.099 * DB saved on disk
09:37:22 redis_s.1 | 33693:M 07 Dec 09:37:22.197 * Background saving terminated with success
09:39:27 worker.1  | 2015-12-07T13:39:27.825Z 33694 TID-ougbxml30 DelayedPaperclip::Jobs::ActiveJob JID-9570d2fa326ad3b1bbc24651 INFO: start
09:39:28 worker.1  | 2015-12-07T13:39:28.299Z 33694 TID-ougbxml30 DelayedPaperclip::Jobs::ActiveJob JID-9570d2fa326ad3b1bbc24651 INFO: fail: 0.474 sec
09:39:28 worker.1  | 2015-12-07T13:39:28.300Z 33694 TID-ougbxml30 WARN: {"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"DelayedPaperclip::Jobs::ActiveJob", "queue"=>"paperclip", "args"=>[{"job_class"=>"DelayedPaperclip::Jobs::ActiveJob", "job_id"=>"44d6026e-5aca-4a07-9d18-054e75bd0eb7", "queue_name"=>"paperclip", "arguments"=>["TaskTran", 449, "signature_manager"], "locale"=>"es"}], "retry"=>true, "jid"=>"9570d2fa326ad3b1bbc24651", "created_at"=>1449495208.7341068, "apartment"=>"companydemo", "enqueued_at"=>1449495567.8203, "error_message"=>"One of the following schema(s) is invalid: \"companydemo\" \"public\"", "error_class"=>"Apartment::TenantNotFound", "failed_at"=>1449495209.205343, "retry_count"=>4, "retried_at"=>1449495568.298719}
09:39:28 worker.1  | 2015-12-07T13:39:28.300Z 33694 TID-ougbxml30 WARN: Apartment::TenantNotFound: One of the following schema(s) is invalid: "companydemo" "public"
09:39:28 worker.1  | 2015-12-07T13:39:28.301Z 33694 TID-ougbxml30 WARN: /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/postgresql_adapter.rb:92:in `rescue in connect_to_new'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/postgresql_adapter.rb:85:in `connect_to_new'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/abstract_adapter.rb:84:in `switch!'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-1.0.2/lib/apartment/adapters/abstract_adapter.rb:97:in `switch'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/apartment-sidekiq-0.2.0/lib/apartment/sidekiq/middleware/server.rb:4:in `call'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/logging.rb:30:in `with_context'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/server/logging.rb:7:in `call'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:129:in `block in invoke'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:132:in `call'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/middleware/chain.rb:132:in `invoke'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/processor.rb:51:in `block in process'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/processor.rb:104:in `stats'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sidekiq-3.5.3/lib/sidekiq/processor.rb:50:in `process'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/calls.rb:28:in `public_send'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/calls.rb:28:in `dispatch'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/call/async.rb:7:in `dispatch'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/cell.rb:50:in `block in dispatch'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/cell.rb:76:in `block in task'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/actor.rb:339:in `block in task'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/task.rb:44:in `block in initialize'
09:39:28 worker.1  | /Users/IFrank/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/celluloid-0.17.2/lib/celluloid/task/fibered.rb:14:in `block in create'

Posted in In-App Navbar Notifications Discussion

Thank you thank you thank you!

Posted in Group records by month to display in a chart

thankyou thats the best solution.

Posted in Group records by month to display in a chart

Chris How can I filter the queries with out duplicating the code so much as Im breaking my head. I like to keep it all dry up and few querys
can you giving me a example of your approach. thankyou.

Posted in Group records by month to display in a chart

Chris if I do.
@tasks = Task.group_by { |t| t.start_date.strftime("%B/%Y")}
@finished = @tasks.select{ |task| task.status == 'Complete' }

I get a error

   NoMethodError: undefined method `status' for "November/2015":String
from (irb):136:in `block in irb_binding'
from (irb):136:in `select'

I think that @tasks its using a K,V and when im reading the .select{ |task| task.status} its doing this

 k = "November/2015"
 k.status

Posted in Group records by month to display in a chart

Chris can I use any of this scope for that??

scope :cancel, lambda {where(:status => "Cancelada")}
scope :unfinish, lambda {where(:status => "Expirada")}
scope :pending, lambda {where(:status => "Pendiente")}
scope :finish, lambda {where(:status => "Completada")}
scope :transfer, lambda {where(:move_task => true)}

Posted in Group records by month to display in a chart

Nice more clean love it what I was looking. Chris Thank you for all the help for the pass few months. my app looks great with all the help.

Posted in Group records by month to display in a chart

    @finish , @unfinish = [], []
@tasks.each do |t|
    @finish << t if t.status == 'Complete'
    @unfinish << t if t.status == 'Cancel'
end

Posted in Group records by month to display in a chart

more details of my problem. Im looking for a way to make the code more dry, has I need to display all the Task, and Task by status. So your getting a bar chart with Task complete, Task Pending and Task cancel. With this code I can display alll task. so now how can I use this code but to display each status on the chart. without duplicating the code.

Controller

@months = Array.new
@total_tasks = Array.new
@tasks = Task.group_by { |t| t.start_date.strftime("%B/%Y")} 
@tasks.reverse_each do |key, value|
    @months << key
    @total_tasks << value.size
end

With this line I get the same output

   Task.group_by_month(:date, format: "%b %Y").count

VIEW

<div id="chart_tasks" style="min-width: 210px; max-width: auto; height: 400px; margin: 0 auto"></div>
<%= javascript_tag do %>
   window.months = JSON.parse('<%= raw @months%>')
   window.total_tasks = JSON.parse('<%= raw @total_tasks%>')
<% end %>

$(function () {
    $('#chart_tasks').highcharts({

        xAxis: {
            categories: months
        }, 

        series: [{
                name: ' Task Total',
                type: 'column', 
                data: total_tasks,
                dataLabels: {
                        enabled: true,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'black'
                    }
            }
    });
});

Posted in Group records by month to display in a chart

Hi Chris Im using HighChart and I have some data that want to display in group by month.

Posted in Subdomains Email reset with Devise

Hi Chris so im trying to work with subdomain and maindomain email reset password
I use the code on devise and for subdomain work like a charm but for the main domain I get this erro because they down have @company.subdomain
https://github.com/plataformatec/devise/wiki/How-To:-Send-emails-from-subdomains

<%= link_to 'Cambiar contraseña', edit_password_url(@resource, reset_password_token: @token, :subdomain => @resource.company.subdomain) %>

any need to use it only if reques is from a subdomain.

Posted in Manage Assets With Rails Assets Discussion

greatwork Chris

Posted in Advice on building a 'reports' feature

@chris will love to see a tutorial on this topic.

@chris im ready to deploy to heroku. how can I setup my cron jobs on heroku or im all set and the whenever gem will setup and tell the cron jobs to run. thank for all the help.

@chris Thank move to sidekiq work out of the box. thank you