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
Related
I'm new to Redmine and Rails, and I have a question I'm stuck with.
I have a timelogger plugin installed from https://github.com/speedy32129/time_logger and it has a redirect option to the IssuesController edit method in Redmine source
https://github.com/speedy32129/time_logger/blob/master/app/controllers/time_loggers_controller.rb#L82
I want to create a custom controller action called edit_realtime, define a route for this and a custom view because I need to do some changes to this view and don't affect the original edit view.
What I've done:
Changed the edit method to edit_realtime in app/controllers/time_loggers_controller.rb:
redirect_to controller: 'issues',
protocol: Setting.protocol,
action: 'edit_realtime',
id: issue_id,
time_entry: { hours: hours }
end
Created a new controller method in app/controllers/issues_controller.rb
def edit_realtime
return unless update_issue_from_params
respond_to do |format|
format.html {}
format.js
end
end
Created a route in routes.rb
post '/issues/new', :to => 'issues#new'
get '/issues/:id/edit_realtime', :to => 'issues#edit_realtime'
Created the needed views in app/views/issue
edit_realtime.html.erb
edit_realtime.js.erb
_edit_realtime.html.erb
The result: 403 error when stopping the time log
View image
full route: http://localhost:81/redmine/issues/1/edit_realtime?time_entry%5Bhours%5D=0.0
and production log
Started GET "/redmine/time_loggers/stop" for 127.0.0.1 at 2021-08-11 16:26:22 +0300
Processing by TimeLoggersController#stop as HTML
Current user: alisa (id=1)
Redirected to http://localhost:81/redmine/issues/1/edit_realtime?time_entry%5Bhours%5D=0.0
Completed 302 Found in 24ms (ActiveRecord: 14.8ms)
Started GET "/redmine/issues/1/edit_realtime?time_entry%5Bhours%5D=0.0" for 127.0.0.1 at 2021-08-11 16:26:22 +0300
Processing by IssuesController#edit_realtime as HTML
Parameters: {"time_entry"=>{"hours"=>"0.0"}, "id"=>"1"}
Current user: alisa (id=1)
Rendering common/error.html.erb within layouts/base
Rendered common/error.html.erb within layouts/base (0.5ms)
Rendered plugins/time_logger/app/views/time_loggers/_embed_menu.html.erb (6.6ms)
Rendered plugins/time_logger/app/views/time_loggers/_update_menu.html.erb (8.5ms) [cache hit]
Filter chain halted as :authorize rendered or redirected
Completed 403 Forbidden in 44ms (Views: 26.3ms | ActiveRecord: 13.1ms)
what did I do wrong?
I am learning AWS in ruby, I have the following code in my controller
sqs = WebService.sqs_client
recieved_message = sqs.receive_message({
queue_url: ENV["SQS_URL"], # required
attribute_names: ["Policy"], # accepts Policy, VisibilityTimeout, MaximumMessageSize, MessageRetentionPeriod, ApproximateNumberOfMessages, ApproximateNumberOfMessagesNotVisible, CreatedTimestamp, LastModifiedTimestamp, QueueArn, ApproximateNumberOfMessagesDelayed, DelaySeconds, ReceiveMessageWaitTimeSeconds, RedrivePolicy
message_attribute_names: ["MessageAttributeName"],
max_number_of_messages: 1,
visibility_timeout: 1,
wait_time_seconds: 1,
})
if recieved_message.size > 0
puts recieved_message[0]
end
puts recieved_message.size
However the output is as follows
Started GET "/employee" for 127.0.0.1 at 2016-08-28 12:43:48 -0500
Processing by PageController#employee as HTML
1
Rendered page/employee.html.erb within layouts/application (2.1ms)
Completed 200 OK in 2020ms (Views: 400.4ms | ActiveRecord: 0.0ms)
I have tried adding .body to the end and various other things all to no avail.
Thanks
I figured it out by studying the example here
I needed to put the following code
puts recieved_message["messages"][0]["body"]
I want to get information from the TwitchTV OAuth API, and the authorization works well, but I can not get the code that Twitch redirects me to.
For example:
http://localhost/?code=noj4n39487fn29fn23v92hr293hnru23v97hre&scope=
This is how Twitch redirects back to my page. In the log of my rails server it also shows the following:
Started GET "/?code=q5yptiyx3cdaep52b7xyqgt3vjpwhg&scope=" for 371.1721.13.179 at 2015-08-22 17:09:26 +0200
Cannot render console from 315.127.134.179! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by HomeController#index as HTML
Parameters: {"code"=>"q5ypti345ferf2rf2efr2erferfe23ff", "scope"=>""}
News Load (0.6ms) SELECT "news".* FROM "news"
Rendered home/index.html.erb within layouts/home (14.7ms)
Completed 200 OK in 124ms (Views: 120.6ms | ActiveRecord: 1.0ms)
But when I try to get params.inspect in the controller, it shows this:
{"controller"=>"oauth", "action"=>"index"}
my controller looks like this:
class OauthController < ApplicationController
def index
redirect_to 'https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=34n87fn48fn438rzfghb4z8rofg4rg&redirect_uri=http://localhost/'
logger.info params.inspect
end
end
Obviously I changed all the ip's, auth-codes and stuff. My question is, shouldn't params return the parameters since it shows them as parameters (in the first code block) ?
Localhost is local address and 'outworld' API cannot send information back to 'localhost', you have to use http://127.0.0.1 or get a real domain for you development environment.
I'm using Rails 3.2.8 with Devise 2.1.2.
If a session times out while the user is still in the app, the next time the user clicks something in the app, it redirects to the signin page. However, the value of session[:user_return_to] is often not what I would expect. In trying to track down the cause, I found that Devise (or Warden) is doing two GETs after receiving a 401 error.
For example, if the user is editing a user and clicks on Update after the session timeout, the log looks like this:
Started PUT "/users/9f276de6-2175-11e3-b8ce-01413834ba1d" for 127.0.0.1 at 2013-10-11 16:43:36 -0700
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"+JP3qXGyUEodmmlLQtpOJpxF8JuEg5sp4Iyjit784Ms=", "user"=>{"first_name"=>...}
User Load (1.5ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = '9b5f6b2e-40bc-31e3-b199-0141337836d6' LIMIT 1
Completed 401 Unauthorized in 9ms
Started GET "/users/9f276de6-2175-11e3-b8ce-01413834ba1d" for 127.0.0.1 at 2013-10-11 16:43:36 -0700
Processing by UsersController#show as HTML
Parameters: {"id"=>"9f276de6-2175-11e3-b8ce-01413834ba1d"}
Completed 401 Unauthorized in 1ms
Started GET "/users/sign_in" for 127.0.0.1 at 2013-10-11 16:43:36 -0700
Processing by Devise::SessionsController#new as HTML
Rendered devise/shared/_links.erb (7.2ms)
Rendered devise/sessions/new.html.erb within layouts/application (21.8ms)
Rendered layouts/_header.html.erb (7.5ms)
Rendered layouts/_flash_messages.html.erb (0.1ms)
Rendered layouts/_footer.html.erb (1.3ms)
Completed 200 OK in 174ms (Views: 171.8ms | ActiveRecord: 0.0ms)
Where is that first GET coming from, i.e. how and why is #show getting called after the first authentication failure?
If I could get rid of that first GET, I'm hoping session[:user_return_to] would remain set to the /users/{:id}/edit path, which is probably where the user will want to go after re-authenticating. As it is, session[:user_return_to] is set to /users/{:id} so they don't go back into edit mode when they log back in.
By the way, even if the failing request is a GET rather than a PUT, I still see an extra GET before it goes to the signin page.
So basically this is bug #2421 reported here:
store_location!() method gets wrong location after timeout
which was addressed by fix #2427:
redirect user to the referrer if latest request was not GET after timeout
As best I can tell, that fix wasn't released until Devise 3.0.0.
Summary for Future Reference
Devise 2.1.2 had this routine in device/failure_app.rb:
def redirect_url
if warden_message == :timeout
flash[:timedout] = true
attempted_path || scope_path
else
scope_path
end
end
With that code, the attempted_path was set from the PUT request, so the first redirect tried to do a GET on the URI used by the PUT (in this case, /users/{:id}). When used with a GET, that URI invokes the #show action.
That code has since been updated to:
def redirect_url
if warden_message == :timeout
flash[:timedout] = true
path = if request.get?
attempted_path
else
request.referrer
end
path || scope_path
else
scope_path
end
end
It looks like that will still do a double-redirect on timeout, but for a PUT, it will use the request.referrer (in this case, /users/{:id}/edit), so session[:user_return_to] should get set correctly.
Update October 25, 2013 I've now upgraded to Devise 3.1.1. As expected, a PUT still does two redirects on timeout, but session[:user_return_to] is set correctly so the user goes back to the referrer on signin.
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!