I'm running this method, and this works perfectly on my local machine but does not work on my remote server. I get that it's looking for a block, but I'm not sure 'where' or 'how' to place it.
Here's my broken method:
def generate_csv
if params[:print_envelopes]
@signups = CardBatch.find(params[:id]).card_signups.each.reject { |a| a.envelope? }
@filename = 'envelopes.csv'
csv_string = FasterCSV.generate do |csv|
csv << ["first name, last name, street address, city, state, zip code"]
@signups.each do |signup|
csv << [signup.first_name, signup.last_name, signup.street_address_1, signup.city, signup.state, signup.zip_code]
signup.envelope = true
signup.save
end
end
elsif params[:print_cards]
@signups = CardBatch.find(params[:id]).card_signups.reject { |a| a.card? }
@filename = 'cards.csv'
csv_string = FasterCSV.generate do |csv|
csv << ["name", "expiration date", "card number"]
@signups.each do |signup|
csv << [signup.full_name, signup.exp_date.strftime('%m/%y'), signup.formatted_card_number] if card?
signup.card = true
signup.save
end
end
end
send_data(csv_string,
:type => 'text/csv; charset=utf-8; header=present',
:filename => @filename)
end
Is there something obvious I'm missing here?
The error:
Processing Admin::CardBatchesController#generate_csv (for 173.161.167.41 at 2010-07-21 07:19:47) [POST]
Parameters: {"action"=>"generate_csv", "authenticity_token"=>"OcDII/t8ZleZxRBpISi+Giw+4MAV2Cjjq8bdixJJ+I8=", "id"=>"4", "controller"=>"admin/card_batches", "print_envelopes"=>"print envelopes"}
LocalJumpError (no block given):
vendor/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:in `method_missing'
app/controllers/admin/card_batches_controller.rb:62:in `generate_csv'
haml (2.2.2) [v] rails/./lib/sass/plugin/rails.rb:19:in `process'
lib/flash_session_cookie_middleware.rb:14:in `call'
vendor/gems/hoptoad_notifier-2.2.2/lib/hoptoad_notifier/rack.rb:27:in `call'
** [Hoptoad] Failure: Net::HTTPClientError
** [Hoptoad] Environment Info: [Ruby: 1.8.6] [Rails: 2.3.3] [Env: production]
** [Hoptoad] Response from Hoptoad:
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>No project exists with the given API key.</error>
</errors>
Rendering /data/HQ_Channel2/releases/20100721141730/public/500.html (500 Internal Server Error)
Update
Ok so I'm getting that if will_paginate is called anywhere within this controller's focus, it will run this function.
Finder.rb around line 170
def method_missing_with_paginate(method, *args) #:nodoc:
# did somebody tried to paginate? if not, let them be
unless method.to_s.index('paginate') == 0
if block_given?
return method_missing_without_paginate(method, *args) { |*a| yield(*a) }
else
return method_missing_without_paginate(method, *args)
end
end
# paginate finders are really just find_* with limit and offset
finder = method.to_s.sub('paginate', 'find')
finder.sub!('find', 'find_all') if finder.index('find_by_') == 0
options = args.pop
raise ArgumentError, 'parameter hash expected' unless options.respond_to? :symbolize_keys
options = options.dup
options[:finder] = finder
args << options
paginate(*args) { |*a| yield(*a) if block_given? }
end
And for some reason this function, and my function written above do not match up. If I can solve that, then this ticket can be closed.