My app has a page allowing users to send me an email through a form (without my address being published). It's associated with an Email controller and is the #new action, which I rerouted to '/contact'.
The weird thing, is if the email doesn't send off for any reason (the user left a field blank or failed the math captcha I put in), when the controller renders "new" again, the url becomes '/emails'. I can't figure this one out at all. Some relevant code:
#emails_controller.rb
require 'math_captcha'
class EmailsController < ApplicationController
def new
#captcha = MathCaptcha.new
#email = Email.new
end
def create
#captcha = MathCaptcha.decrypt(params[:captcha_secret])
#email = Email.new(params[:email])
unless #captcha.correct?(params[:captcha]) || params[:captcha] == "21261"
flash.now[:error] = "Please make sure you answered the math question correctly."
render :new
else
if #email.save
Contact.contact_message(#email).deliver
flash[:success] = "Your email has sent! I'll try to get back to you shortly."
redirect_to root_path
else
flash.now[:error] = "Please correct the highlighted errors and try again."
render :new
end
end
end
end
And:
#routes.rb
resources :users, :posts, :sessions, :emails
#...
match '/contact', to: 'emails#new', as: 'contact'
The same problem was there before I added "as contact" in an attempt to fix it. Any ideas?
EDIT -- per garbage collection's request (sorry for the delay; haven't been near my computer for a bit), here's the dev log for navigating to /contact and submitting an unsuccessful email attempt (which refreshes and changes the URL to /emails):
Started GET "/contact" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Processing by EmailsController#new as HTML
Rendered emails/new.html.erb within layouts/application (1.5ms)
Rendered layouts/_shim.html.erb (0.0ms)
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
Rendered layouts/_header.html.erb (2.0ms)
Completed 200 OK in 20ms (Views: 19.5ms | ActiveRecord: 0.1ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /application.css - 304 Not Modified (2ms)
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /custom.css - 304 Not Modified (2ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /angular.js - 304 Not Modified (0ms)
Started GET "/assets/pygments.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /pygments.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-transition.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-affix.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-alert.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-button.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-carousel.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-collapse.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-modal.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-dropdown.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-scrollspy.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-popover.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-tab.js - 304 Not Modified (46ms)
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-typeahead.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /bootstrap-tooltip.js - 304 Not Modified (0ms)
Started GET "/assets/emails.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /emails.js - 304 Not Modified (0ms)
Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /posts.js - 304 Not Modified (0ms)
Started GET "/assets/expand.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /expand.js - 304 Not Modified (0ms)
Started GET "/assets/sessions.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /sessions.js - 304 Not Modified (0ms)
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /users.js - 304 Not Modified (0ms)
Started GET "/assets/statics.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /statics.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:40 -1000
Served asset /application.js - 304 Not Modified (0ms)
Started GET "/posts.json" for 127.0.0.1 at 2013-02-16 08:46:41 -1000
Processing by PostsController#index as JSON
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 2]]
[1m[35mPost Load (0.2ms)[0m SELECT "posts".* FROM "posts"
Completed 200 OK in 7ms (Views: 3.3ms | ActiveRecord: 0.4ms)
Started GET "/assets/sign_out.png" for 127.0.0.1 at 2013-02-16 08:46:41 -1000
Served asset /sign_out.png - 304 Not Modified (0ms)
Started POST "/emails" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Processing by EmailsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"hjd4q/tvu6IhqpdC7rPMkS21s0GTiqILqOA8ZkLKXsk=", "email"=>{"name"=>"", "address"=>"", "subject"=>"", "content"=>""}, "captcha_secret"=>"xmuKN1l8HVyPlbsfymoVWTieuFYYO3qcXoUUawh8vyw=\r\n", "captcha"=>"", "commit"=>"Send"}
Rendered emails/new.html.erb within layouts/application (1.7ms)
Rendered layouts/_shim.html.erb (0.0ms)
[1m[36mUser Load (0.1ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1[0m [["id", 2]]
Rendered layouts/_header.html.erb (2.5ms)
Completed 200 OK in 25ms (Views: 22.0ms | ActiveRecord: 0.1ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /application.css - 304 Not Modified (2ms)
Started GET "/assets/pygments.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /pygments.css - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-transition.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/angular.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /angular.js - 304 Not Modified (0ms)
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /custom.css - 304 Not Modified (1ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-affix.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-button.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-alert.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-carousel.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-modal.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-collapse.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-dropdown.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-scrollspy.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-tooltip.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-tab.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-typeahead.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap.js - 304 Not Modified (0ms)
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /bootstrap-popover.js - 304 Not Modified (0ms)
Started GET "/assets/expand.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /expand.js - 304 Not Modified (0ms)
Started GET "/assets/emails.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /emails.js - 304 Not Modified (0ms)
Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /posts.js - 304 Not Modified (0ms)
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /users.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /application.js - 304 Not Modified (1ms)
Started GET "/assets/sessions.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /sessions.js - 304 Not Modified (0ms)
Started GET "/assets/statics.js?body=1" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /statics.js - 304 Not Modified (0ms)
Started GET "/posts.json" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Processing by PostsController#index as JSON
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
[1m[36mPost Load (0.2ms)[0m [1mSELECT "posts".* FROM "posts" [0m
Completed 200 OK in 5ms (Views: 2.3ms | ActiveRecord: 0.3ms)
Started GET "/assets/sign_out.png" for 127.0.0.1 at 2013-02-16 08:46:44 -1000
Served asset /sign_out.png - 304 Not Modified (0ms)
It's expected to show '/emails' in the address bar since you just POST'ed to that url. If you really want to show '/contact', you should set up a route for POST like:
get '/contact', to: 'emails#new'
post '/contact', to: 'emails#create'
Maybe there's another, more concise way to do it, but this should work.
Related
When I click 'log out' I can see that Rails processess the request, but I'm still logged in.
Any clue why this happens? Both locally and on Heroku.
Started DELETE "/users/sign_out" for IP at 2014-11-18 08:32:46 +0000
Processing by Devise::SessionsController#destroy as HTML
Parameters: {"authenticity_token"=>"TOKEN"}
Redirected to http://example.com/
Completed 302 Found in 14ms (ActiveRecord: 4.4ms)
Started GET "/" for 84.215.64.133 at 2014-11-18 08:32:47 +0000
Processing by StaticPagesController#blog as HTML
Rendered static_pages/blog.html.slim within layouts/application (0.7ms)
Completed 200 OK in 6ms (Views: 2.9ms | ActiveRecord: 1.6ms)
routes.rb
devise_for :users
From the log when editing a user:
Started PUT "/users" for 84.215.64.133 at 2014-11-18 14:40:30 +0000
Processing by Devise::RegistrationsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QR/p3BAG+ocmacss5xDjuFDfhFSA+iv6VRK37uA9HcQ=", "user"=>{"mobile"=>"93441707", "email"=>"sss#
strosin.info", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Lagre"}
2014-11-18T14:40:31.095730+00:00 app[web.2]: App 131 stdout: Redirected to http://
The problem disapeared when I cleared the browser cache. (Using Chrome beta).
In my code I have this :
def confirm
#pal = Pal.find(params[:palid])
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone
if #newuser.save
redirect_to(:controller => 'access', :action => 'index')
else
flash[:error] = "Retry."
render template: 'pals/new_password_asign'
end
end
private
def newuser_params
params.require(:newuser).permit(:username, :password_digest, :password_stored)
end
and after submitting my sign up form, I get redirected and the error "Retry" which I've specified.
Knowing that I create users and save them via rails console perfectly fine.
And this has got me thinking what would possibly prevent this from being saved?
What issues might occur during the saving?
======================================================
Rails v4
Ruby v2.02
I am using Bcrypt-ruby for authentication.
======================================================
Update #1
=======================================================
After adding the suggested solution of #mandeep, I now do get the error explanation, and in this explanation I get
" Password can't be blank "
Despite the fact that I do write the password before submiting
Check my sign up form
<%= form_for(:newuser, :url => {:action => 'confirm', :palid => #pal.id}) do |f| %>
<% if #newuser.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#newuser.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #newuser.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<table summary="user form fields">
<tr>
<th><%= f.label(:username, "User Name") %></th>
<td><%= f.text_field :username, :value => #newuser.username, :class => "controls", :disabled => "true" %></td>
</tr>
<tr>
<th><%= f.label(:password, "password") %></th>
<td><%= f.password_field(:password) %></td>
</tr>
</table>
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
</div>
<% end %>
<% #newuser.password_stored = #newuser.password %>
</div>
</body>
==============================================
Update #2
Log and params after being request by #mandeep
Started GET "/pals" for 127.0.0.1 at 2014-07-03 16:15:44 +0000
ActiveRecord::SchemaMigration Load (0.1ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by palsController#index as HTML
pal Load (0.4ms) SELECT `pals`.* FROM `pals`
Rendered pals/index.html.erb within layouts/application (9.8ms)
Completed 200 OK in 280ms (Views: 260.9ms | ActiveRecord: 0.4ms)
Started GET "/pals" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Processing by palsController#index as HTML
pal Load (0.7ms) SELECT `pals`.* FROM `pals`
Rendered pals/index.html.erb within layouts/application (6.3ms)
Completed 200 OK in 103ms (Views: 101.4ms | ActiveRecord: 0.7ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:45 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:15:46 +0000
Started GET "/pals/new" for 127.0.0.1 at 2014-07-03 16:16:11 +0000
Processing by PalsController#new as HTML
Rendered pals/_form.html.erb (24.7ms)
Rendered pals/new.html.erb within layouts/application (43.6ms)
Completed 200 OK in 106ms (Views: 101.2ms | ActiveRecord: 1.6ms)
Started POST "/pals" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Processing by PalsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "pal"=>{"owner"=>"John", "title"=>"", "phone"=>"22", "price"=>"", "logtype"=>"", "description"=>"", "address"=>"", "latitude"=>"", "longitude"=>""}, "commit"=>"Create pal"}
(0.3ms) BEGIN
SQL (0.3ms) INSERT INTO `pals` (`address`, `created_at`, `description`, `logtype`, `owner`, `phone`, `title`, `updated_at`) VALUES ('', '2014-07-03 16:16:19', '', '', 'John', '22', '', '2014-07-03 16:16:19')
(56.6ms) COMMIT
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`username` = '22'
Redirected to http://localhost:3000/pals/confirm?palid=5
Completed 302 Found in 77ms (ActiveRecord: 58.1ms)
Started GET "/pals/confirm?palid=5" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Processing by PalsController#confirm as HTML
Parameters: {"palid"=>"5"}
pal Load (0.6ms) SELECT `pals`.* FROM `pals` WHERE `pals`.`id` = 5 LIMIT 1
Rendered pals/confirm.html.erb within layouts/application (6.4ms)
Completed 200 OK in 63ms (Views: 52.4ms | ActiveRecord: 0.8ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:19 +0000
Started POST "/pals/confirm?palid=5" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Processing by PalsController#confirm as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "newuser"=>{"password"=>"[FILTERED]"}, "commit"=>"Save Newuser", "palid"=>"5"}
pal Load (0.2ms) SELECT `pals`.* FROM `pals` WHERE `pals`.`id` = 5 LIMIT 1
(0.6ms) BEGIN
(0.1ms) COMMIT
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Rendered pals/confirm.html.erb within layouts/application (1.8ms)
Completed 200 OK in 60ms (Views: 50.6ms | ActiveRecord: 1.1ms)
Started GET "/assets/access.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/pals.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:29 +0000
Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/pals.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/access.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-07-03 16:16:30 +0000
If you look at your code
def confirm
pal = Pal.find(params[:palid]) # you have find your pal and store it in "pal"
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone # you are using instance variable "#pal" which is not defined
# your other logic
end
Instead you should have your code like:
def confirm
#pal = Pal.find(params[:palid])
#newuser = User.new(newuser_params)
#newuser.username = #pal.phone
# your other logic
end
Also in your form you should put this code
<% if #newuser.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#newuser.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #newuser.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
This will display if there are any validation errors in your form. For details refer to here
Update:
If you look at the parameters which are being passed from your form, notice this
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8X6LD0g6E1HybdAF/FOlM09iuQLWExBY8dY5CqSDZsM=", "newuser"=>{"password"=>"[FILTERED]"}, "commit"=>"Save Newuser", "palid"=>"5"}
There are couple of things wrong in your form:
a. Either you didn't enter your username in form or you haven't made your form properly because in params it's only showing password field "newuser"=>{"password"=>"[FILTERED]"}
b. You haven't permit your password field instead of permitting password you have permitted :password_digest, :password_stored. Your newuser_params should look like this:
def newuser_params
params.require(:newuser).permit(:username, :password)
end
c. what is "palid"=>"5" doing in your params? Is it a field in your form or what because it's not associated to newuser params
Check the validation errors in #newuser, namely #newuser.errors. There are methods that skip validations. Maybe you are using them in the console.
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 followed this Geocoder Railscast & I'm playing around with it to see if I can add validation to the longitude & latitude coordinates returned by the Geocoder Gem incase the user inputs a faulty address that does not return any longitude & latitude coordinates.
I was able to get this working to a point with the code below but when I enter a correct address it gives the user a validation error the first time they submit the form, even though longitude & latitude coordinates where returned. The second time the user submits the form it works.
I suspect this is happening as when the user submits the form there are no longitude & latitude coordinates but there are the second time round as the geocoder gem returned the coordinates.
Is there something wrong with my code or should I be approaching this differently?
Model
class Location < ActiveRecord::Base
attr_accessible :address1,
:country,
:latitude,
:longitude,
:name
validates :latitude, :presence => {message: "Not a valid location on Google Maps, please check name address & country fields" }
geocoded_by :address
after_validation :geocode, :if => :address_changed?
def address
[name, address1, country].compact.join(' ')
end
def address_changed?
attrs = %w(name address1 country)
attrs.any?{|a| send "#{a}_changed?"}
end
end
Terminal OutPut
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-04-02 02:03:41] INFO WEBrick 1.3.1
[2013-04-02 02:03:41] INFO ruby 1.9.3 (2013-02-22) [x86_64-linux]
[2013-04-02 02:03:41] INFO WEBrick::HTTPServer#start: pid=4316 port=3000
Started POST "/locations" for 127.0.0.1 at 2013-04-02 02:04:04 +0100
Processing by LocationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"4HUay+IOgA7JnCSg8ZZ0zVMcHpj7djUPlfqe1emTMSY=", "location"=>{"name"=>"Louch Dan", "address1"=>"Roundwood", "town"=>"", "county"=>"", "state"=>"", "country"=>"Ireland", "latitude"=>"", "longitude"=>""}, "commit"=>"Create Location"}
(0.1ms) begin transaction
(0.1ms) rollback transaction
Rendered locations/_form.html.erb (8.9ms)
Rendered locations/new.html.erb within layouts/application (63.4ms)
Completed 200 OK in 410ms (Views: 156.1ms | ActiveRecord: 6.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /application.css - 304 Not Modified (11ms)
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /jquery_ujs.js - 304 Not Modified (1ms)
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /jquery.js - 304 Not Modified (7ms)
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /scaffolds.css - 304 Not Modified (1ms)
Started GET "/assets/locations.css?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /locations.css - 304 Not Modified (1ms)
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/locations.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /locations.js - 304 Not Modified (4ms)
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:06 +0100
Served asset /application.js - 304 Not Modified (7ms)
[2013-04-02 02:04:06] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started POST "/locations" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Processing by LocationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"4HUay+IOgA7JnCSg8ZZ0zVMcHpj7djUPlfqe1emTMSY=", "location"=>{"name"=>"Louch Dan", "address1"=>"Roundwood", "town"=>"", "county"=>"", "state"=>"", "country"=>"Ireland", "latitude"=>"53.07004130000001", "longitude"=>"-6.2804327"}, "commit"=>"Create Location"}
(0.1ms) begin transaction
SQL (15.3ms) INSERT INTO "locations" ("address1", "country", "county", "created_at", "latitude", "longitude", "name", "state", "town", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["address1", "Roundwood"], ["country", "Ireland"], ["county", ""], ["created_at", Tue, 02 Apr 2013 01:04:22 UTC +00:00], ["latitude", 53.07004130000001], ["longitude", -6.2804327], ["name", "Louch Dan"], ["state", ""], ["town", ""], ["updated_at", Tue, 02 Apr 2013 01:04:22 UTC +00:00]]
(71.9ms) commit transaction
Redirected to http://0.0.0.0:3000/locations/10
Completed 302 Found in 236ms (ActiveRecord: 87.3ms)
Started GET "/locations/10" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Processing by LocationsController#show as HTML
Parameters: {"id"=>"10"}
Location Load (3.8ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = ? LIMIT 1 [["id", "10"]]
Rendered locations/show.html.erb within layouts/application (9.8ms)
Completed 200 OK in 25ms (Views: 15.5ms | ActiveRecord: 3.8ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /application.css - 304 Not Modified (0ms)
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/locations.css?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /locations.css - 304 Not Modified (0ms)
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /jquery.js - 304 Not Modified (6ms)
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /scaffolds.css - 304 Not Modified (0ms)
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /application.js - 304 Not Modified (43ms)
Started GET "/assets/locations.js?body=1" for 127.0.0.1 at 2013-04-02 02:04:22 +0100
Served asset /locations.js - 304 Not Modified (0ms)
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2013-04-02 02:04:22] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
Why can't you :geocode the Location before validation? :address_changed? will return true even for new records if any of those fields have changed. Validate it and if it returns invalid lat/lng values then your :latitude presence validation will fail.
Just change that after_validation to before_validation.
<%= 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.