<%= link_to 'show', :controller=>:users, :action=>:show, :id=>u.id, :confirm=>'are you sure?' %>
<%= link_to 'reset pass.', :controller=>:users, :action=>:reset_password, :id=>u.id, :confirm=>'RESET PASSWORD, are you sure?' %>
The first link works fine, but the second is really strange... sometimes it works, and sometimes is doesn't and causes such an error:
LoadError in UsersController#index
Expected
/home/anonym/Documents/RubyOnRails/authorisation/loginout/app/controllers/users_controller.rb
to define UsersController
Moreover it doesn't show confirmation box. Anyway if I remove :confirm option the first error occurs anyway from time to time.
Controller:
#users_controller.rb
class UsersController < ApplicationController
...
def reset_password
#user=User.find_by_id(params[:id])
...
Routes:
#routes.rb
match 'users/:id/reset_password', :to=>"users#reset_password"
It could be understandable to me if it failed everytime but is it's kind of random.
Any ideas why?
UPDATE
This little modification in controller seemed to fix the problem.
#Thread.new{UserMailer.reset_password(#user, passwd).deliver}
UserMailer.reset_password(#user, passwd).deliver
This also caused my sqlite database to collapse (if I clicked the link very fast a few times).
Do you know why this thread might have been such a killer?
And there still is the question why there is no confirmation box?
UPDATE
Started GET "/users/2/reset_password?confirm=RESET+PASSWORD%2C+are+you+sure%3F" for 127.0.0.1 at 2012-02-06 15:03:57 +0100
Processing by UsersController#reset_password as HTML
Parameters: {"confirm"=>"RESET PASSWORD, are you sure?", "id"=>"2"}
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1[0m
[1m[35mUser Load (0.4ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[1m[36m (0.5ms)[0m [1mSELECT 1 FROM "users" WHERE ("users"."email" = 'my_email#gmail.com' AND "users"."id" != 2) LIMIT 1[0m
[1m[35m (0.3ms)[0m UPDATE "users" SET "last_support_email_sent_time" = '2012-02-06 14:03:58.182567', "encrypted_password" = '5380187f533d14e2867667f8c2c9dc6671b1d930ff892a8cb4da7cdda99d01c8', "updated_at" = '2012-02-06 14:03:58.186194' WHERE "users"."id" = 2
Rendered /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/views/user_mailer/reset_password.html.erb (0.2ms)
Sent mail to my_email#gmail.com (1270ms)
Date: Mon, 06 Feb 2012 15:03:58 +0100
from: User service
To: my_email#gmail.com
Message-ID: <4f2fddce433d3_2c275ca2fa664560#anonym-laptop.mail>
Subject: Your new password
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Hello ,</br>
Your new password is: 469ff56728
Redirected to http://localhost:3000/users
Completed 302 Found in 1407ms
Started GET "/users" for 127.0.0.1 at 2012-02-06 15:03:59 +0100
Processing by UsersController#index as HTML
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1[0m
[1m[35mUser Load (1.1ms)[0m SELECT "users".* FROM "users" ORDER BY email
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.1ms)
Rendered shared/_add_to_user_index_row.html.erb (0.2ms)
Rendered /home/anonym/Documents/RubyOnRails/authorisation/loginout/app/views/users/index.html.erb within layouts/application (75.8ms)
Completed 200 OK in 197ms (Views: 132.5ms | ActiveRecord: 2.6ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/loginout.css" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /loginout.css - 404 Not Found (39ms)
ActionController::RoutingError (No route matches [GET] "/assets/loginout.css"):
Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.1ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /jquery.js - 304 Not Modified (1ms)
Started GET "/assets/messages.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /messages.js - 304 Not Modified (1ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /application.js - 304 Not Modified (2ms)
Started GET "/assets/auth_engine.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /auth_engine.css - 304 Not Modified (2ms)
Started GET "/assets/sessions.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /sessions.css - 304 Not Modified (0ms)
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2012-02-06 15:04:00 +0100
Served asset /users.css - 304 Not Modified (0ms)
Started GET "/users" for 127.0.0.1 at 2012-02-06 15:04:35 +0100
SQLite3::SQLException: unsupported file format: SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
ActiveRecord::StatementInvalid (SQLite3::SQLException: unsupported file format: SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
):
After that database is broken - server restart doesn't help. This occures from time to time eventhough I no longer use Threads.
Rails is not thread-safe. If you need to perform background operations, use something like Spawn or DelayedJob
As for the confirmation, do you have an application.js in your app/assets/javascript folder, and do you have <%= javascript_include_tag "application" %> in the <head> of your layout?
If the application.js file isn't being loaded, none of the Rails JS will run, which includes confirmations.
Update: I see the problem now. The link_to method takes two types of options, first the options for routing, then the options for the HTML. :confirm is one of the HTML options.
If you're going to pass routing and HTML options, you need to separate the routing options into their own hash first, like so:
<%= link_to 'show', { :controller=>:users, :action=>:show, :id=>u.id }, :confirm=>'are you sure?' %>
<%= link_to 'reset pass.', { :controller=>:users, :action=>:reset_password, :id=>u.id }, :confirm=>'RESET PASSWORD, are you sure?' %>
As the log demonstrates, your confirm is being passed as part of the path generated by the link_to, rather than being included in the HTML of the generated a element.
Related
I generate Model first
rails g model cat name
Then I genarate Scaffold Controller with the model name
rails g scaffold_controller zoo/cat name --model-name=zoo/cat
Then I add route
namespace :zoo do
resources :cats
end
Then I edit the Model
class Zoo::Cat < ActiveRecord::Base
end
The funny thing is it fails at first, with error
LoadError in Zoo::CatsController#index
Unable to autoload constant Cat, expected /home/minh/Desktop/fnl110/app/models/cat.rb to define it
def index
#zoo_cats = Zoo::Cat.all
end
Then I reload the page, it works without any error. Here is what server said:
Started GET "/zoo/cats" for 127.0.0.1 at 2016-01-10 21:05:30 +0700
ActiveRecord::SchemaMigration Load (0.1ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by Zoo::CatsController#index as HTML
Completed 500 Internal Server Error in 14ms (ActiveRecord: 0.0ms)
LoadError (Unable to autoload constant Cat, expected /home/minh/Desktop/fnl110/app/models/cat.rb to define it):
app/controllers/zoo/cats_controller.rb:7:in `index'
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.1ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.2ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (29.2ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.5ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.4ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.4ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (19.6ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.5ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms)
Rendered /home/minh/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (42.4ms)
Started GET "/zoo/cats" for 127.0.0.1 at 2016-01-10 21:10:15 +0700
Processing by Zoo::CatsController#index as HTML
Zoo::Cat Load (0.2ms) SELECT `cats`.* FROM `cats`
Rendered zoo/cats/index.html.erb within layouts/application (8.6ms)
Completed 200 OK in 200ms (Views: 197.5ms | ActiveRecord: 1.2ms)
Started GET "/assets/animal/bears.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/cats.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/dogs.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/scaffolds.self-d5c911709e0018272624ff2abf5748b5d0ff72c54f791bb9bcefd817c3322285.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/turbolinks.self-c37727e9bd6b2735da5c311aa83fead54ed0be6cc8bd9a65309e9c5abe2cbfff.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/jquery_ujs.self-d456baa54c1fa6be2ec3711f0a72ddf7a5b2f34a6b4f515f33767d6207b7d4b3.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/application.self-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/bears.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/jquery.self-a714331225dda820228db323939889f149aec0127aeb06255646b616ba1ca419.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/dogs.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/application.self-3b8dabdc891efe46b9a144b400ad69e37d7e5876bdc39dee783419a69d7ca819.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
Started GET "/assets/animal/cats.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" for 127.0.0.1 at 2016-01-10 21:10:16 +0700
P/S: The reason of
rails g scaffold_controller zoo/cat name --model-name=zoo/cat
is
rails g scaffold_controller zoo/cat --model-name=zoo/cat
=> controller doesn't take model attributes
and
rails g scaffold_controller zoo/cat --model-name=cat
=> Error: undefined local variable or method `new_cat_path'
The error is normal, your model should be moved in the zoo directory, so app/models/zoo/cat.rb (instead of app/models/cat.rb). If you do that it will work immediately.
I might be wrong, but I believe the following happens:
When you load the page the first time, rails will lazily load the models, and will give you the error not because of the request, but because the file app/models/cat.rb should define Cat and not Zoo::Cat;
Even with the error, rails will have loaded the Zoo::Cat model, so when you reload the page, it won't encounter the error because the models have already been loaded, thus the request succeeds.
I'm using rails 3.2 and Devise 3.4.1.
On development environment all is working great but on production I'm getting this:
Started POST "/users/sign_in" for 111.111.111.11 at 2015-01-18 15:04:58 +0000
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"PGRrSKfVz8fZiv1a1qBJN2TzmFRAvUgEfYRpmdWiPWk=", "user"=>{"email"=>"email#email.com", "password"=>"[FILTERED]"}, "commit"=>"Log in"}
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'email#email.com' LIMIT 1
(0.2ms) BEGIN
(0.5ms) UPDATE `users` SET `last_sign_in_at` = '2015-01-18 15:04:53', `current_sign_in_at` = '2015-01-18 15:04:59', `sign_in_count` = 25, `updated_at` = '2015-01-18 15:04:59' WHERE `users`.`id` = 2
(1.2ms) COMMIT
Redirected to http://subdomain.domain.com/
Completed 302 Found in 100.0ms (ActiveRecord: 0.0ms)
Started GET "/" for 111.111.111.11 at 2015-01-18 15:04:59 +0000
Started GET "/authorized" for 111.111.111.11 at 2015-01-18 15:04:59 +0000
Processing by AuthorizedController#index as HTML
Completed 401 Unauthorized in 0.3ms
Started GET "/users/sign_in" for 111.111.111.11 at 2015-01-18 15:05:00 +0000
Processing by SessionsController#new as HTML
Rendered devise/shared/_links.html.erb (0.1ms)
Rendered devise/sessions/new.html.erb (4.0ms)
Completed 200 OK in 5.3ms (Views: 4.5ms | ActiveRecord: 0.0ms)
as you can see the user is being authorised but signing out immediately after that.
help?
well, the CDN just blocked Devise's cookie so it's solved now
thank you all!
After successfully logging in to my rails application in production mode, I will attempt to click on one of the filter buttons at the top of the table: 'All Servers', 'In Progress', or 'Remediation.' After pressing one of these buttons, the session will be destroyed and redirect the user back to the login page; however, this does not occur in the development environment. In the dev environment, when the user presses one of the filter buttons, the proper scope is applied and no redirection occurs.
After comparing the production logs to the development logs, the error appears to manifest in Devise::SessionsController#new
Source code can be found at: https://github.com/herman5/warthog
I have the application hosted on Heroku, so the effects can be seen.
URL: http://testdomain.dcmdashboard.com
email: moderator#example.com
password: password
After logging in and pressing a filter button (GET "/?order=id_desc&page=1&scope=in_progress") in the dev environment:
Started POST "/users/sign_in" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"UmLj+rzYzRWPr/Y7G5q2Y+/6KptI6X1EzoE7xJCjCIQ=", "user"=>{"email"=>"moderator#example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Tenant Load (1.4ms) SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'testdomain' LIMIT 1
User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'moderator#example.com' LIMIT 1
(1.6ms) BEGIN
(2.5ms) UPDATE "users" SET "last_sign_in_at" = '2013-12-30 00:14:55.058879', "current_sign_in_at" = '2013-12-30 01:40:15.445913', "sign_in_count" = 3, "updated_at" = '2013-12-30 01:40:15.450781' WHERE "users"."id" = 3
(1.6ms) COMMIT
Redirected to http://testdomain.warthog.dev/admin
Completed 302 Found in 131ms (ActiveRecord: 1.0ms)
Started GET "/admin" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Processing by Admin::ServersController#index as HTML
Tenant Load (1.7ms) SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'testdomain' LIMIT 1
User Load (32.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
(2.8ms) SELECT COUNT(*) FROM "servers" WHERE ('t')
(2.5ms) SELECT COUNT(*) FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA')
(4.0ms) SELECT COUNT(*) FROM "servers" WHERE (build_stage = '7 - Build Team Remediation' OR build_stage = '13 - SecOps Remediation')
(2.4ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" LIMIT 30 OFFSET 0) subquery_for_count
(2.6ms) SELECT COUNT(*) FROM "servers"
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" LIMIT 30 OFFSET 0) subquery_for_count
Server Load (2.6ms) SELECT "servers".* FROM "servers" ORDER BY "servers"."id" desc LIMIT 30 OFFSET 0
Rendered /Users/Dylan/.rvm/gems/ruby-1.9.3-p392/bundler/gems/active_admin-ec9996406df5/app/views/active_admin/resource/index.html.arb (354.6ms)
Completed 200 OK in 403ms (Views: 342.4ms | ActiveRecord: 54.0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/lib/namespace.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /active_admin/components/jquery.aa.checkbox-toggler.js - 304 Not Modified (0ms)
Served asset /active_admin/lib/namespace.js - 304 Not Modified (0ms)
Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Started GET "/assets/active_admin/components/jquery.aa.dropdown-menu.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:15 -0600
Served asset /jquery-ui.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.table-checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/components/jquery.aa.dropdown-menu.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.popover.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/components/jquery.aa.table-checkbox-toggler.js - 304 Not Modified (4ms)
Started GET "/assets/active_admin/pages/batch_actions.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/components/jquery.aa.popover.js - 304 Not Modified (5ms)
Started GET "/assets/active_admin/pages/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/pages/batch_actions.js - 304 Not Modified (4ms)
Served asset /active_admin/pages/application.js - 304 Not Modified (3ms)
Started GET "/assets/active_admin/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/application.js - 304 Not Modified (9ms)
Started GET "/assets/active_admin/base.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin/base.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:16 -0600
Served asset /active_admin.js - 304 Not Modified (0ms)
Started GET "/?order=id_desc&page=1&scope=in_progress" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Processing by Admin::ServersController#index as HTML
Parameters: {"order"=>"id_desc", "page"=>"1", "scope"=>"in_progress"}
Tenant Load (2.4ms) SELECT "tenants".* FROM "tenants" WHERE "tenants"."subdomain" = 'testdomain' LIMIT 1
(2.6ms) SELECT COUNT(*) FROM "servers" WHERE ('t')
(4.3ms) SELECT COUNT(*) FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA')
(2.8ms) SELECT COUNT(*) FROM "servers" WHERE (build_stage = '7 - Build Team Remediation' OR build_stage = '13 - SecOps Remediation')
(2.3ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(*) FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA')
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') LIMIT 30 OFFSET 0) subquery_for_count
Server Load (2.6ms) SELECT "servers".* FROM "servers" WHERE (build_stage = '2 - In Progress' OR build_stage = '4 - Build Team QA') ORDER BY "servers"."id" desc LIMIT 30 OFFSET 0
Rendered /Users/Dylan/.rvm/gems/ruby-1.9.3-p392/bundler/gems/active_admin-ec9996406df5/app/views/active_admin/resource/index.html.arb (359.3ms)
Completed 200 OK in 373ms (Views: 349.4ms | ActiveRecord: 19.5ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /jquery-ui.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.checkbox-toggler.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.popover.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.popover.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/pages/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/pages/application.js - 304 Not Modified (0ms)
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/application.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Started GET "/assets/active_admin/lib/namespace.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/application.js - 304 Not Modified (0ms)
Served asset /active_admin/lib/namespace.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.dropdown-menu.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.dropdown-menu.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/components/jquery.aa.table-checkbox-toggler.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/components/jquery.aa.table-checkbox-toggler.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/pages/batch_actions.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/pages/batch_actions.js - 304 Not Modified (0ms)
Started GET "/assets/active_admin/base.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin/base.js - 304 Not Modified (12ms)
Started GET "/assets/active_admin.js?body=1" for 127.0.0.1 at 2013-12-29 19:40:26 -0600
Served asset /active_admin.js - 304 Not Modified (0ms)
After logging in and pressing the filter button (GET "/?order=id_desc&page=1&scope=in_progress") in the production environment:
Started POST "/users/sign_in" for 127.0.0.1 at 2013-12-29 19:47:10 -0600
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"UmLj+rzYzRWPr/Y7G5q2Y+/6KptI6X1EzoE7xJCjCIQ=", "user"=>{"email"=>"moderator#example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Redirected to http://testdomain.warthog.dev/admin
Completed 302 Found in 116ms (ActiveRecord: 1.8ms)
Started GET "/admin" for 127.0.0.1 at 2013-12-29 19:47:11 -0600
Processing by Admin::ServersController#index as HTML
Rendered /Users/Dylan/.rvm/gems/ruby-1.9.3-p392/bundler/gems/active_admin-ec9996406df5/app/views/active_admin/resource/index.html.arb (115.1ms)
Completed 200 OK in 126ms (Views: 97.7ms | ActiveRecord: 24.6ms)
Started GET "/?order=id_desc&page=1&scope=in_progress" for 127.0.0.1 at 2013-12-29 19:47:23 -0600
Processing by Devise::SessionsController#new as HTML
Parameters: {"order"=>"id_desc", "page"=>"1", "scope"=>"in_progress"}
Rendered devise/shared/_links.haml (0.3ms)
Rendered devise/sessions/new.html.haml within layouts/application (3.2ms)
Completed 200 OK in 14ms (Views: 7.2ms | ActiveRecord: 4.4ms)
After playing around with the hosted version I think the problem is in the links used to sort the server table. You currently use the link http://testdomain.dcmdashboard.com/?order=operating_system_desc to order the table by the operating system. If you use http://testdomain.dcmdashboard.com/admin/?order=operating_system_desc instead (with /admin/ in front of your query param) your session don't get killed and you don't have to log in again.
This problem does only exist for those columns with your self defined collections in app/admin/servers.rb. It may be a bug in the current development version of active_admin or a missing parameter.
Please add a value for the default namespace in config/initializers/active_admin.rb:
config.default_namespace = :admin
Should the problem persist try to use a stable version of active_admin like version 0.6.2 and try it again.
Only difference between production and development is that production logs you out when you follow links that get you out of the /admin namespace, problem is present in both cases, it looks like an ActiveAdmin bug.
Keeping in touch with good people at active admin will help https://github.com/gregbell/active_admin/issues/2839
Also, while using ActiveAdmin for VERY simple apps and scaffolding is well and OK, you will rue the day you decided doing anything complex with it, in the time lost fixing this one scope you probably could have built the entire thing from scratch using ransack and devise
I have a simple login system that works in the browser. I recently switched my cucumber tests to use selenium because I need ajax calls and now the login/auth steps do not pass anymore. The app still functions normally in firefox and chromium.
Here are the Steps and the definitions
features/authentication.features
Feature: Require Authentication
In order to restrict access to the app
A User
Must be logged in
Scenario: Accessing Tracks
Given I am not logged in
And I visit the "Tracks" page
Then I should see the "Welcome" page
And I should see "You need to be logged in to access this page"
Scenario: Accessing Tracks when Logged in
Given I am logged in
And I visit the "Tracks" page
Then I should see the "Tracks" page
features/step_definitions/register_and_login_steps.rb
When(/^I log in as "(.*?)"$/) do |name|
create_and_login(name)
end
When(/^I log in$/) do
create_and_login('tester')
end
When(/^I log out$/) do
visit(logout_path)
end
When(/^I should be logged out$/) do
page.should have_title "Welcome"
page.should have_text "Please log in"
end
When(/^I am( not)? logged in$/) do |negative|
if negative
visit(logout_path)
else
create_and_login('anyone')
page.should have_title 'Welcome'
end
end
features/step_definitions/should_see_steps.rb
When(/I should( not)? see the "(.*?)" page$/) do |negative, page_title|
if negative
page.should_not have_title page_title
else
page.should have_title page_title
end
end
When(/^I should( not)? see "(.*?)"$/) do |negative, text|
if negative
page.should_not have_text text
else
page.should have_text text
end
end
When(/^I visit the "(.*?)" page$/) do |page|
path = page.downcase + "_path"
visit_path(path)
end
features/support/helpers/user.rb
def password_for(user)
user + '_password_'
end
def create_user(name)
return if User.exists?(name: name)
user = User.create!(name: name,
password: password_for(name),
password_confirmation: password_for(name))
end
def create_and_login(name)
create_user(name)
visit(logout_path)
visit(login_path)
fill_in 'Name', with: name
fill_in 'Password', with: password_for(name)
click_button 'Login'
end
Gemfile (test group only)
group :test do
gem 'guard-spork', '~> 1.5.0'
gem 'rb-inotify', '~> 0.9.0'
gem 'spork', '~> 0.9.2'
gem 'guard-rspec','~> 2.5.0'
gem 'cucumber-rails' , '~> 1.3.0'
gem 'database_cleaner','~> 0.9.1'
gem 'guard-cucumber', '~> 1.3.2'
gem 'capybara', '~> 2.1.0'
gem 'selenium-webdriver', '~>2.31.0'
end
log/test.log
Connecting to database specified by database.yml
(0.3ms) begin transaction
Started GET "/logout" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Processing by SessionsController#destroy as HTML
Redirected to http://127.0.0.1:42286/login
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
Started GET "/login" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (26.4ms)
Rendered layouts/_player.html.haml (0.9ms)
Completed 200 OK in 64ms (Views: 63.6ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.js" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Served asset /application.js - 200 OK (8ms)
Started GET "/assets/application.css" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Served asset /application.css - 200 OK (3ms)
Started GET "/tracks" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Processing by TracksController#index as HTML
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."session" = '' LIMIT 1
Redirected to http://127.0.0.1:42286/login
Filter chain halted as :require_login rendered or redirected
Completed 302 Found in 62ms (ActiveRecord: 1.6ms)
Started GET "/login" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (1.8ms)
Rendered layouts/_player.html.haml (0.1ms)
Completed 200 OK in 4ms (Views: 3.8ms | ActiveRecord: 0.0ms)
(0.1ms) rollback transaction
(0.0ms) begin transaction
User Exists (1.1ms) SELECT 1 AS one FROM "users" WHERE "users"."name" = 'anyone' LIMIT 1
(0.0ms) SAVEPOINT active_record_1
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."name" = 'anyone' LIMIT 1
User Exists (0.0ms) SELECT 1 AS one FROM "users" WHERE "users"."session" IS NULL LIMIT 1
Binary data inserted for `string` type on column `password_digest`
Binary data inserted for `string` type on column `session`
SQL (0.3ms) INSERT INTO "users" ("admin", "created_at", "name", "password_digest", "session", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["admin", nil], ["created_at", Sun, 21 Apr 2013 23:57:49 UTC +00:00], ["name", "anyone"], ["password_digest", "$2a$10$2kPN1wqnXI/G9b/1KMR2x.7yCHCaKwftE7PXm/q4u9Q9bcWCTenMG"], ["session", "91e2394dcdc86ada3836b258ad6bd2c850f99e03"], ["updated_at", Sun, 21 Apr 2013 23:57:49 UTC +00:00]]
(0.0ms) RELEASE SAVEPOINT active_record_1
Started GET "/logout" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Processing by SessionsController#destroy as HTML
Redirected to http://127.0.0.1:42286/login
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
Started GET "/login" for 127.0.0.1 at 2013-04-22 01:57:49 +0200
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (0.9ms)
Rendered layouts/_player.html.haml (0.0ms)
Completed 200 OK in 2ms (Views: 1.9ms | ActiveRecord: 0.0ms)
Started GET "/login" for 127.0.0.1 at 2013-04-22 01:57:50 +0200
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (0.9ms)
Rendered layouts/_player.html.haml (0.0ms)
Completed 200 OK in 2ms (Views: 2.0ms | ActiveRecord: 0.0ms)
Started POST "/sessions" for 127.0.0.1 at 2013-04-22 01:57:50 +0200
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "session"=>{"name"=>"anyone", "password"=>"[FILTERED]"}, "commit"=>"Login"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."name" = 'anyone' LIMIT 1
Redirected to http://127.0.0.1:42286/login
Completed 302 Found in 2ms (ActiveRecord: 0.2ms)
Started GET "/login" for 127.0.0.1 at 2013-04-22 01:57:50 +0200
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (0.8ms)
Rendered layouts/_player.html.haml (0.1ms)
Completed 200 OK in 2ms (Views: 1.8ms | ActiveRecord: 0.0ms)
Started GET "/tracks" for 127.0.0.1 at 2013-04-22 01:57:50 +0200
Processing by TracksController#index as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."session" = '' LIMIT 1
Redirected to http://127.0.0.1:42286/login
Filter chain halted as :require_login rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.2ms)
Started GET "/login" for 127.0.0.1 at 2013-04-22 01:57:50 +0200
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (27.5ms)
Rendered layouts/_player.html.haml (0.0ms)
Completed 200 OK in 29ms (Views: 28.9ms | ActiveRecord: 0.0ms)
(0.1ms) rollback transaction
The fix was to not set selenium as the default capybara driver and tag the tests that require ajax with #javascript.
I'm using rails 3 + devise. When a user signs up and there is an error. The app is redirecting to:
http://localhost:3000/users
Showing the error messages, but in the log I see the following:
Started POST "/users" for 127.0.0.1 at Mon Jul 11 20:22:19 -0700 2011
Processing by RegistrationsController#create as HTML
Parameters: {"commit"=>"Create my account", "fb_access_token"=>"XXXXX", "authenticity_token"=>"fWd/XXXX=", "utf8"=>"✓", "user"=>{"remember_me"=>"0", "lname"=>"XXXX", "fname"=>"XXXX", "password"=>"[FILTERED]", "email"=>"XXXX-inc.com"}, "fb_uuid"=>"312312"}
SQL (0.1ms) BEGIN
User Load (0.2ms) SELECT "users"."id" FROM "users" WHERE ("users"."email" = 'brett#companyline-inc.com') LIMIT 1
SQL (0.2ms) ROLLBACK
Rendered layouts/_header.html.erb (1.1ms)
Rendered registrations/new.html.erb within layouts/unauthorized (11.3ms)
Completed 200 OK in 45ms (Views: 22.6ms | ActiveRecord: 2.7ms)
Started GET "/users" for 127.0.0.1 at Mon Jul 11 20:22:20 -0700 2011
ActionController::RoutingError (No route matches "/users"):
Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.8ms)
routes.rb:
# OmniAuth - for FB Connect
match '/users/auth/facebook/callback' => 'authentications#create'
# Devise
devise_for :users, :controllers => {:registrations => "registrations"}
Why the actionController error?
What does rake routes show you? The order in which you place your routes matters also, since the Rails router picks the first route it matches.
Hope this helps!