I get this in my server log, which seems to indicate that it returned ajaxresponse.js.erb:
Started GET "/ajaxresponse" for 70.28.21.25 at 2013-10-01 15:38:54 +0000
Processing by ContentController#ajaxresponse as JS
Rendered content/ajaxresponse.js.erb within layouts/content (0.5ms)
Rendered inc/_analytics.erb (0.3ms)
Completed 200 OK in 46ms (Views: 45.3ms | ActiveRecord: 0.0ms)
Inside ajaxresponse.js.erb :
$('#ajaxdiv').append("fdsa");
There is a div on the page with ID "ajaxdiv"
but it doesn't seem to change anything? I've tried 100 different javascript commands within the .js.erb file, but none of them are affecting the page.
Controller action:
def ajaxresponse
respond_to do |format|
format.js {}
end
end
Chrome console log :
Uncaught Error: jquery-ujs has already been loaded!
Edit: Just remoted jquery-ujs from the application.rb file and there are no more errors. The page, however, still doesn't update with ajax
The ajaxdiv is below the save button and has default text: "ohai"
To get a div with the id "ajaxdiv", you need to use #ajaxdiv, not ajaxdiv:
$('#ajaxdiv').append("fdsa");
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 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
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!
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