I am trying to use the next page token from the first page results that are retrieved by the call to the Google Places, using the following code:
def pins_in_area
#client = GooglePlaces::Client.new('api_key_XXXXX')
#results = #client.spots(params[:lat], params[:long], :radius => params[:radius])
puts #results
next_page_token = #results.last.nextpagetoken
puts next_page_token #spots_by_pagetoken
next_spots = #client.spots_by_pagetoken(next_page_token)
puts next_spots
...
end
But, I encounter the following error, not sure why:
Completed 500 Internal Server Error in 258ms (ActiveRecord: 0.0ms)
GooglePlaces::InvalidRequestError (GooglePlaces::InvalidRequestError):
app/controllers/api/v1/pins_controller.rb:89:in `pins_in_area'
Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (13.1ms)
Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (35.1ms)
Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)
Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (101.1ms)
Related
Hi everybody I'm trying to use wicked pdf in rails.
Get a pdf based on the object generated by the query, #questions
When downloading the pdf, the query data is lost.
when I visit "/simulators.pdf" it shows me the following error in console
Started GET "/simulators.pdf" for 127.0.0.1 at 2018-11-01 12:38:19 -0500
Processing by SimulatorsController#index as PDF
Test Load (0.2ms) SELECT "tests".* FROM "tests" WHERE "tests"."name" IS NULL LIMIT $1 [["LIMIT", 1]]
CACHE Test Load (0.0ms) SELECT "tests".* FROM "tests" WHERE "tests"."name" IS NULL LIMIT $1 [["LIMIT", 1]]
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.2ms)
NoMethodError (undefined method `id' for nil:NilClass):
Controller:
def index
#test = Test.find_by(name: params[:test])
#questions = TestQuestion.joins(:test).where(test_id: #test.id).order('RANDOM()').limit(10)
respond_to do |format|
format.html
format.pdf { render template: 'simulators/pdf', pdf: 'pdf'}
end
end
URL:
http://localhost:3000/simulators?test=biology
This is url of index view
Can you help me?
Many thanks
that's because when you ask for the pdf, you need to send the query in the url too
http://localhost:3000/simulators.pdf?test=biology
if you don't send the variable in the url, the search that you are doing will be nil, that's the error you are having.
I have this defined in my application_mailer.rb
def request_tutor(contact_name, contact_hp, contact_email, postal_code, contact_level, contact_subject, contact_lessons, contact_hours, contact_others)
#contact_name = contact_name
#contact_hp = contact_hp
#contact_email = contact_email
#contact_postal = postal_code
#contact_level = contact_level
#contact_subject = contact_subject
#contact_lesson = contact_lessons
#contact_hours = contact_hours
#contact_others = contact_others
mail(to:'example#example.com', subject: 'Tutor Request')
end
and in the respective controller where the view is supposed to be rendered
def request_tutor
contact_name = params[:request_tutor][:contact_name]
contact_email = params[:request_tutor][:contact_email]
contact_hp = params[:request_tutor][:contact_hp]
contact_postal = params[:request_tutor][:postal_code]
contact_level = params[:request_tutor][:contact_level]
contact_subject = params[:request_tutor][:contact_subject]
contact_lesson = params[:request_tutor][:contact_lessons]
contact_hours = params[:request_tutor][:contact_hours]
contact_others = params[:request_tutor][:contact_others]
ApplicationMailer.request_tutor(contact_name, contact_hp, contact_email, postal_code, contact_level, contact_subject, contact_lessons, contact_hours, contact_others).deliver
flash[:success] = "We have received your request and will be in touch with you shortly!"
redirect_to root_path
end
I have a similar method setup in action mailer too and in the respective controller i'm doing name = params[:checkout][:your_name] and it doesn't return the error undefined method '[]' for nil:NilClass. What am i missing?
Errors from development.log
Started GET "/" for 116.87.14.150 at 2016-10-10 23:02:37 +0000
Cannot render console from 116.87.14.150! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
[1m[36mActiveRecord::SchemaMigration Load (0.5ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
Processing by WelcomeController#index as HTML
Rendered welcome/index.html.erb within layouts/application (390.7ms)
Rendered layouts/_nav.html.erb (5.9ms)
Rendered layouts/_messages.html.erb (0.6ms)
Rendered layouts/_footer.html.erb (0.8ms)
Completed 200 OK in 641ms (Views: 608.3ms | ActiveRecord: 0.0ms)
Started GET "/welcome/request" for 116.87.14.150 at 2016-10-10 23:02:43 +0000
Cannot render console from 116.87.14.150! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by WelcomeController#request_tutor as HTML
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `[]' for nil:NilClass):
app/controllers/welcome_controller.rb:16:in `request_tutor'
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (6.4ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.8ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.5ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (110.0ms)
ok, so you are using the same action to both set up the form, and also to create the email. This is where the problem comes in... because when you first click on the form - it will run the request_tutor action, but there is no params[:request_tutor] yet (because you haven't submitted the form yet)... so you need to check for that to exist before trying to create one.
eg this is possible:
def request_tutor
if params[:request_tutor].present?
contact_name = params[:request_tutor][:contact_name]
# ... lines skipped for brevity
# you still need the ones in your original action
ApplicationMailer.request_tutor(contact_name, contact_hp, contact_email, postal_code, contact_level, contact_subject, contact_lessons, contact_hours, contact_others).deliver
flash[:success] = "We have received your request and will be in touch with you shortly!"
redirect_to root_path
end
# If the code gets to here, there were no params, and the page
# will just render the template named the same as the action
end
I have a bunch of logger.debug statements in my Controller. They currently write the place where all the HTTP requests and everything are displayed in real time on my WEBRick server. However,
when I write logger.debug statements in my Model, they are not written to this same location, additionally they are not to be found in log/development which is the environment I have been working in. It is particularly frustrating because I make the call to the following Model function in a controller that has successfully executed logger.debug statements:
def process_payment
uri = URI('https://demo.myvirtualmerchant.com/VirtualMerchant/processxml.do')
the_xml = SchoolApplication.to_xml(params[:credit_card],
params[:expiration],
params[:cvv2_cvc2],
params[:amount],
params[:name])
logger.debug(the_xml)
the_xml = the_xml.to_s
my_hash = {'xmldata' => the_xml}
logger.debug(the_xml)
response = Net::HTTP.post_form(uri, my_hash)
#response_var = response
if response.response == 0
render 'receipt'
else
render 'card_Error'
end
end
the two logger.debug statements in this controller method are written to what I suppose is STDOUT? In any case I see them in the location which displays the following kind of information:
Rendered web_applications/card_Error.html.erb within layouts/application (1.7ms)
Completed 200 OK in 433ms (Views: 13.1ms | ActiveRecord: 0.0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-22 11:32:02 -0700
In the above Controller method when I make the call to SchoolApplication.to_xml,
it does not execute the corresponding logger.debug() statements (or maybe it writes them
to a different place? That wouldn't make sense but I am also a n00b, clearly) that are in
to_xml Model method as shown below:
def self.to_xml(number,expiration,cvv,amount, name)
xml = ::Builder::XmlMarkup.new
logger.debug(number)
logger.debug(name)
xml.txn {
xml.ssl_test_mode false
xml.ssl_card_number number
xml.ssl_amount amount
xml.ssl_cvv2cvc2_indicator cvv
xml.ssl_first_name name
xml.ssl_show_form false
xml.ssl_exp_date '25/34'
xml.ssl_track_data
xml.ssl_result_format HTML
xml.ssl_receipt_link_method
xml.ssl_receipt_link_url "#{Rails.root}" + '/receipts/receive'
xml.ssl_receipt_link_text
}
xml
end
N.B. I know that the above to_xml is being successfully called and returned from as the rest of my controller method which calls this model function executes without error.
Here is the output after I go to the route which calls the process_payment controller function:
Started POST "/application/pay" for 127.0.0.1 at 2014-07-22 12:13:40 -0700
Processing by WebApplicationsController#process_payment as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"pJD6Q7qJPXFNaGEczv5kTSKBC5TcG8lqhOuLNjw9UrY=", "web_application"=>{"first_name"=>"bob", "last_name"=>"job", "card_number"=>"41111111111111", "expiration_date"=>"232", "cvv2_cvc2"=>"232"}, "commit"=>"Save Web application"}
<txn><ssl_merchant_id/><ssl_user_id/><ssl_ssl_pin/><ssl_test_mode>false</ssl_test_mode> <ssl_card_number/><ssl_amount/><ssl_cvv2cvc2_indicator/><ssl_first_name/ ><ssl_show_form>false</ssl_show_form><ssl_exp_date>25/34</ssl_exp_date><ssl_track_data/><ssl_result_format>HTML</ssl_result_format><ssl_receipt_link_method/><ssl_receipt_link_url> <ssl_receipt_link_text/></txn><to_s/>
<txn><ssl_merchant_id/><ssl_user_id/><ssl_ssl_pin/><ssl_test_mode>false</ssl_test_mode> <ssl_card_number/><ssl_amount/><ssl_cvv2cvc2_indicator/><ssl_first_name/><ssl_show_form>false</ssl_show_form><ssl_exp_date>25/34</ssl_exp_date><ssl_track_data/><ssl_result_format>HTML</ssl_result_format><ssl_receipt_link_method/>
Rendered web_applications/card_Error.html.erb within layouts/application (3.8ms)
Completed 200 OK in 742ms (Views: 22.6ms | ActiveRecord: 0.0ms)
which is equivalent to what was written in development.log
Okay, here's the deal I can't figure out at the moment.
So, I have this action looking like this:
def get
#page = Page.find_by_title(params[:title])
respond_to do |format|
format.html # get.html.erb
format.js # get.js.coffee
end
end
Which, depending on whether it's an AJAX call or a normal GET request, the renders either get.html.erb or get.js.coffee.
In development, that is, as shown by the following log entry:
Started GET "/pages/medien/get" for 127.0.0.1 at 2011-12-11 18:58:31 +0100
Processing by PagesController#get as JS
Parameters: {"title"=>"medien"}
Rendered pages/_get.html.erb (153.0ms)
Rendered pages/get.js.coffee (1185.0ms)
Completed 200 OK in 1230ms (Views: 1220.0ms | ActiveRecord: 5.0ms)
In production the same request and same code results in a log entry like this:
Started GET "/pages/medien/get/" for 91.11.86.230 at 2011-12-11 18:57:44 +0100
Processing by PagesController#get as JS
Parameters: {"title"=>"medien"}
Read fragment views/mypage/pages/medien/get (0.1ms)
Rendered pages/_get.html.erb (0.8ms)
Rendered pages/get.html.erb (0.9ms)
Completed 200 OK in 2ms (Views: 1.5ms | ActiveRecord: 0.2ms)
I simply don't get why it's even stating that it's processing it as JavaScript but then does not execute the javascript in get.js.coffee without even throwing an error!
I am using Rails 3.0.7, kaminari gem.
I just built a simple site, with SQLite database and 100,000 rows of data, with just four columns (ID, name, created_at, updated_at).
This is my controller:
class HclinksController < ApplicationController
# GET /hclinks
# GET /hclinks.xml
def index
#hclinks = Hclink.page(params[:page])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => #hclinks }
end
end
end
I scaffolded it.
Here's my log:
// THIS IS INDEX, WHICH SHOWS ALL THE LIST ITEMS
Started GET "/hclinks" for 127.0.0.1 at 2011-05-08 00:59:52 +0800
Processing by HclinksController#index as HTML
Hclink Load (391.8ms) SELECT "hclinks".* FROM "hclinks" LIMIT 25 OFFSET 0
SQL (4574.8ms) SELECT COUNT(*) FROM "hclinks"
Rendered hclinks/index.html.erb within layouts/application (178778.1ms)
Completed 200 OK in 182775ms (Views: 175845.5ms | ActiveRecord: 4966.6ms)
// THIS IS THE RUBY ON RAILS WELCOME PAGE
Started GET "/hclinks" for 127.0.0.1 at 2011-05-08 01:03:13 +0800
Processing by HclinksController#index as HTML
Hclink Load (65.3ms) SELECT "hclinks".* FROM "hclinks" LIMIT 25 OFFSET 0
SQL (910.6ms) SELECT COUNT(*) FROM "hclinks"
Rendered hclinks/index.html.erb within layouts/application (1532.2ms)
Completed 200 OK in 1657ms (Views: 652.5ms | ActiveRecord: 975.9ms)
I wonder why the list took so long to respond... How should I fix it? Thanks!
Is this log output from a fresh restart of rails or had the app already run a few requests?
If this wasn't the first request, I'd check if the load time increases on each request.
If it does, you may have a memory leak