Rails 3.1.3 custom routing by date - ruby-on-rails

How to make path helpers for this route?
resources :news
match 'news/:year/:month/:day' => 'news#show',
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ },
:as => 'newsdate'
I tried it many ways, but it not works:
link_to news.created_at.strftime '%d.%m.%Y ', newsdate_path(:year => '2011', :month => '11', :day => '11')
I get app error for this line by GET http://localhost:3000/news:
ArgumentError in News#index
Showing /home/foxweb/work/dev/app/views/news/index.html.slim where line #6 raised:
wrong number of arguments (2 for 1)
How to make it right way?
P.S. http://localhost:3000/news/2011/11/11 works fine.

Oh, that's common mistake. You need to take strftime arguments in braces.
link_to news.created_at.strftime('%d.%m.%Y'), newsdate_path(:year => '2011', :month => '11', :day => '11')
That's all!

Related

How to use `date_select` with `:use_month_names`

I am using date_select. It has default months (January, February etc.). I want to change it, and add custom months (Ukraine month). I found an option for this, but I don't understand how it works.
This is my attempt:
<%= ht.date_select :data, :start_year => Date.current.year,
:use_month_names => {January: 'Січень',
:February => 'Лютий', :March => 'Березень', :April => 'Квітень',
:May => 'Травень', :June => 'Червень', :July => 'Липень', :August =>
'Серпень',
:September => 'Вересень', :October => 'Жовтень', :November =>
'Листопад', :December => 'Грудень' } %>
How does this option :use_month_names work?
From the docs it seems you have to pass an array with those names. Try
<%= ht.date_select :data, :start_year => Date.current.year,
:use_month_names => ['Січень', 'Лютий', 'Березень','Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень'] %>

Print "signature_required" option in Fedex label - Rails

I'm using the fedex gem version 3.9 and cannot get the "signature required" option printed on my fedex label.
This is how it looks:
label = fedex.label(
:filename => "public/labels/#{label_name}",
:shipper => shipper,
:recipient => recipient,
:packages => packages,
:service_type => service_type,
:signature_required => true,
:shipping_options => shipping_options)
I remember this used to work a couple of months ago but now it doesn't.
Let me know if you have any suggestions.
Best,
Turns out that the signature options should be sent as part of the packages. Then it prints the label with the right signature initials
packages = [{
:weight => {:units => "LB", :value => 3},
:dimensions => {:length => 10, :width => 5, :height => 4, :units => "IN" },
:special_services_requested => {:special_service_types => "SIGNATURE_OPTION", :signature_option_detail => {:signature_option_type => "DIRECT"} }
}]
label = fedex.label(
:filename => "public/labels/#{label_name}",
:shipper => shipper,
:recipient => recipient,
:packages => packages
:shipping_options => shipping_options)

Inconsistent display of checkboxes on PDF form filled with PDFtk

I am filling PDF forms in my rails app with the pdf-forms (https://github.com/jkraemer/pdf-forms) gem, based on PDFtk. Text fields work as I would expect, but my checkbox fields do not. The boxes display well in Chrome, but in Preview and Mail the checkbox fields appear empty.
class FormsController < ApplicationController
require 'pdf_forms'
def acord25
#policy = Policy.find(params[:id])
pdftk = PdfForms.new('/usr/local/bin/pdftk')
# find out the field names that are present in form.pdf
pdftk.get_field_names 'lib/pdfs/acord25.pdf'
# take form.pdf, set the 'foo' field to 'bar' and save the document to myform.pdf
pdftk.fill_form '/lib/pdfs/acord25.pdf', "acord25.pdf",
"F[0].P1[0].Form_CompletionDate_A[0]" => #policy.dateIssued,
"F[0].P1[0].Producer_FullName_A[0]" => #policy.client.broker.name,
"F[0].P1[0].Producer_MailingAddress_LineOne_A[0]" => #policy.client.broker.company,
"F[0].P1[0].Producer_MailingAddress_LineTwo_A[0]" => #policy.client.broker.address,
"F[0].P1[0].Producer_ContactPerson_FullName_A[0]" => #policy.legalVesting,
"F[0].P1[0].Producer_ContactPerson_PhoneNumber_A[0]" => #policy.client.broker.phone,
"F[0].P1[0].Producer_FaxNumber_A[0]" => #policy.client.broker.fax,
"F[0].P1[0].Producer_ContactPerson_EmailAddress_A[0]" => #policy.client.broker.email,
"F[0].P1[0].NamedInsured_FullName_A[0]" => #policy.client.name,
"F[0].P1[0].NamedInsured_MailingAddress_LineOne_A[0]" => #policy.client.address.titlecase,
"F[0].P1[0].GeneralLiability_CoverageIndicator_A[0]" => 1,
"F[0].P1[0].GeneralLiability_OccurrenceIndicator_A[0]" => 1,
"F[0].P1[0].GeneralLiability_GeneralAggregate_LimitAppliesPerLocationIndicator_A[0]" => 1,
"F[0].P1[0].Policy_PolicyNumberIdentifier_A[0]" => #policy.policyNumber,
"F[0].P1[0].Policy_EffectiveDate_A[0]" => #policy.dateEffective,
"F[0].P1[0].PolicyExpirationGeneral[0]" => #policy.term.dayEnd,
"F[0].P1[0].Insurer_FullName_A[0]" => "Lexington Insurance Company",
"F[0].P1[0].Insurer_NAICCode_A[0]" => 19437,
"F[0].P1[0].Insurer_FullName_B[0]" => "Commerce & Industry Insurance Company",
"F[0].P1[0].Insurer_NAICCode_B[0]" => 19410,
"F[0].P1[0].Insurer_FullName_C[0]" => "Great American Insurance Company",
"F[0].P1[0].Insurer_NAICCode_C[0]" => 37532,
"F[0].P1[0].Insurer_FullName_D[0]" => "Admiral Insurance Company",
"F[0].P1[0].Insurer_NAICCode_D[0]" => 24856,
"F[0].P1[0].GeneralLiability_InsurerLetterCode_A[0]" => "A",
"F[0].P1[0].GeneralLiability_EachOccurrence_LimitAmount_A[0]" => 1000000,
"F[0].P1[0].GeneralLiability_FireDamageRentedPremises_EachOccurrenceLimitAmount_A[0]" => 50000,
"F[0].P1[0].GeneralLiability_MedicalExpense_EachPersonLimitAmount_A[0]" => "Excluded",
"F[0].P1[0].GeneralLiability_PersonalAndAdvertisingInjury_LimitAmount_A[0]" => 1000000,
"F[0].P1[0].GeneralLiability_GeneralAggregate_LimitAmount_A[0]" => 2000000,
"F[0].P1[0].GeneralLiability_ProductsAndCompletedOperations_AggregateLimitAmount_A[0]" => 2000000,
"F[0].P1[0].Vehicle_InsurerLetterCode_A[0]" => "A",
"F[0].P1[0].Vehicle_HiredAutosIndicator_A[0]" => 1,
"F[0].P1[0].Vehicle_NonOwnedAutosIndicator_A[0]" => 1,
"F[0].P1[0].Policy_PolicyNumberIdentifier_B[0]" => #policy.policyNumber,
"F[0].P1[0].Policy_EffectiveDate_B[0]" => #policy.dateEffective,
"F[0].P1[0].Policy_ExpirationDate_B[0]" => #policy.term.dayEnd,
"F[0].P1[0].Vehicle_CombinedSingleLimit_EachAccidentAmount_A[0]" => 1000000,
"F[0].P1[0].ExcessUmbrella_InsurerLetterCode_A[0]" => "B",
"F[0].P1[0].ExcessUmbrella_OccurrenceIndicator_A[0]" => 1,
"F[0].P1[0].ExcessUmbrella_DeductibleIndicator_A[0]" => 1,
"F[0].P1[0].ExcessUmbrella_Umbrella_DeductibleOrRetentionAmount_A[0]" => #policy.coverages.first.deductibleOcc,
"F[0].P1[0].Policy_PolicyNumberIdentifier_D[0]" => #policy.policyNumber,
"F[0].P1[0].Policy_EffectiveDate_D[0]" => #policy.dateEffective,
"F[0].P1[0].Policy_ExpirationDate_D[0]" => #policy.term.dayEnd,
"F[0].P1[0].ExcessUmbrella_Umbrella_EachOccurrenceAmount_A[0]" => 10000000,
"F[0].P1[0].ExcessUmbrella_Umbrella_AggregateAmount_A[0]" => 10000000
send_file("#{Rails.root}/acord25.pdf", filename: "#{#policy.client.name} - #{#policy.carrier.name} - #{#policy.policyNumber} (#{Time.now}).pdf", type: "application/vnd.ms-excel")
end
end
TL;DR: Checked boxes display in Chrome, but not in Preview or Mail.
I appreciate any help or leads on what the problem might be. Thank you!
Turns out the PDF form was corrupted. Had to recreate form, not a PDFTK issue.

rails functional testing issue

When I do
get :inside, :format => :xml, :lat2 => "41", :lng2 => "-73.9", :lat1 => "40", :lng1 => "-74", :category => "girl", :order => "date"
with my routes.rb includes:
get 'images/inside/:lat1/:lng1/:lat2/:lng2/:order/:category', :to => "images#inside"
I get
ActionController::RoutingError: No route matches {:lng1=>"-74", :category=>"girl", :lat2=>"41", :format=>:xml, :lng2=>"-73.9", :order=>"date", :lat1=>"40", :action=>"inside", :controller=>"images"}
But when I do
get :inside, :format => :xml, :lat2 => "41", :lng2 => "-73", :lat1 => "40", :lng1 => "-74", :category => "girl", :order => "date"
it works!
The only difference is the decimal value of lng2.
Note that if routes.rb has no params, it works, but I need those
As far as I can tell, it's because your value has a period. By default, Rails (at least Rails3) routes cannot contain periods. To work around this, see http://avdi.org/devblog/2010/06/18/rails-3-resource-routes-with-dots-or-how-to-make-a-ruby-developer-go-a-little-bit-insane/
I bet the decimal point is making Rails think that there's a format being specified (e.g. .xml or .js).
You might be able to get around it using a regex, something like what's described here: http://zargony.com/2009/05/05/routing-parameters-with-a-dot

ruby gem flickr-fu license problem

I've trying to get the flickr-fu gem to search correctly only for commercial friendly photos but with no luck. It seems to ignore the parameter altogether.
photos = flickr.photos.search(:text => "anything",
:tags => 'architecture',
#:license_id => '4,6,5',
:license_id => [0,4,5,6],
#:license_id => 0,
:content_type => '1',
:safe_search => '1',
:sort => 'date-posted-asc, relevance',
:per_page => 5)
The license IDs 1,2,3 are NonCommercial, so I'm trying to avoid those and take all others, but it doesn't seem to matter, i'm still getting a lot of 3s in my query.
http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
http://github.com/commonthread/flickr_fu/blob/master/lib/flickr/photos.rb
Nevermind, this seems to work.
photos = flickr.photos.search(:text => "anything",
:tags => 'architecture',
:license => '0,4,5,6',
:content_type => '1',
:safe_search => '1',
:sort => 'date-posted-asc, relevance',
:per_page => 5)

Resources