Validating longitude / latitude with geocoder gem - ruby-on-rails

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.

Related

Rails send files starting multiple GETs

I have 2 Rails apps, App1 and App2.
App1 contains links to controller actions in App2 which in turn returns files (downloads), e.g.:
<%= link_to "Download Video", "http://app2/downloads/download_video", :target => "_bkank" %>
with "downloads" being and controller within App2 and "download_video" being an action of the "downloads" controller:
def download_video
send_file '/path/to/video/video.mp4', type: "video/mp4", :disposition => "inline"
end
Upon clicking the link, a new window (tab) is opened and the video is played in the window - this is a desired behavior .... my problem is, when looking t the logs, I see that the same GET request is sent 3 times - the first as HTML and then as / twice:
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:45 +0200
Processing by DownloadsController#download_video as HTML
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 0ms
Could anyone let me know why this is happening and how I can prevent it?
Thanks,
Jon.
#praga2050,
can you please post entire controller code ...
yes:
class DownloadsController < ApplicationController
def download_video
send_file '/var/www/videos/video.mp4', type: "video/mp4", :disposition => "inline"
end
end
#praga2050,
... try putting Rails.logger.debug with time stamp and see
yes:
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as HTML
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms

How to update FullCalendar events using a search function?

I have my search set up like so.
# Viewings controller
def index
#rmquery = params[:search]
if params[:search]
#viewings = Viewing.search(params[:search])
else
#viewings = Viewing.all
end
end
and
class Viewing < ActiveRecord::Base
belongs_to :user
belongs_to :room
def self.search(query)
self.where("room_id like ?", "%#{query}%")
end
end
and I have my (viewings) index.jbuilder as follows:
json.array!(#viewings) do |viewing|
json.title "viewing"
json.start viewing.start_time
json.end viewing.end_time
json.url viewing_url(viewing, format: :html)
end
I would like my viewings.json to reflect the search results, but it only seems to display all viewings, even though the search is working under where it says "Listing Viewings"
Ive tried something along the lines of:
#viewings = Viewing.where(room_id: #rmquery)
json.array!(#viewings) do |viewing|
json.title "viewing"
json.start viewing.start_time
json.end viewing.end_time
json.url viewing_url(viewing, format: :html)
end
but it doesn't seem to pass the query through.
oh, and my index view:
<p id="notice"><%= notice %></p>
<%= form_tag(viewings_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search rooms" %>
<%= submit_tag "Search", :name => nil %>
<% end %>
<div id="calendar"> </div>
<h1>Listing Viewings</h1>
<table>
<thead>
<tr>
<th>Room</th>
<th>Customer</th>
<th>Start time</th>
<th>End time</th>
<th>Notes</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #viewings.each do |viewing| %>
<tr>
<td><%= viewing.room_id %></td>
<td><%= viewing.customer_id %></td>
<td><%= viewing.start_time %></td>
<td><%= viewing.end_time %></td>
<td><%= viewing.notes %></td>
<td><%= link_to 'Show', viewing %></td>
<td><%= link_to 'Edit', edit_viewing_path(viewing) %></td>
<td><%= link_to 'Destroy', viewing, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Viewing', new_viewing_path %>
Code for calendar:
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
events: '/viewings.json',
defaultView: 'agendaWeek',
slotMinutes: 60,
})
});
server log for search
C:\Sites\weddings
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-24 22:40:04] INFO WEBrick 1.3.1
[2015-02-24 22:40:04] INFO ruby 1.9.3 (2014-02-24) [i386-mingw32]
[2015-02-24 22:40:04] INFO WEBrick::HTTPServer#start: pid=8260 port=3000
Started GET "/viewings?utf8=%E2%9C%93&search=1" for ::1 at 2015-02-24 22:40:14 +
0000
←[1m←[36mActiveRecord::SchemaMigration Load (1.0ms)←[0m ←[1mSELECT "schema_mi
grations".* FROM "schema_migrations"←[0m
Processing by ViewingsController#index as HTML
Parameters: {"utf8"=>"V", "search"=>"1"}
←[1m←[35mViewing Load (1.0ms)←[0m SELECT "viewings".* FROM "viewings" WHERE (
room_id like '%1%')
Rendered viewings/index.html.erb within layouts/application (52.0ms)
←[1m←[36mUser Load (1.0ms)←[0m ←[1mSELECT "users".* FROM "users" WHERE "user
s"."id" = ? ORDER BY "users"."id" ASC LIMIT 1←[0m [["id", 1]]
Completed 200 OK in 1216ms (Views: 1100.8ms | ActiveRecord: 4.0ms)
Started GET "/assets/fullcalendar-6bee23c458d42683dba9159c94f7547f.css?body=1" f
or ::1 at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/application-4a810b319e4a8061f2f2b27a579eadc1.css?body=1" fo
r ::1 at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/forms-2477fa28d6be1997f320e98a5ceee0f6.css?body=1" for ::1
at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/index-divs-e5867ca540c81afa8a01e2daca2920c5.css?body=1" for
::1 at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/owl.carousel-688ba12698d3c02b724b8a26bc3b1bd0.css?body=1" f
or ::1 at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/owl.theme-f91781dace0c67e4d6a689ddd73d65b7.css?body=1" for
::1 at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/owl.transitions-1b9d47a45c85e9fa3f2f990b6d59519a.css?body=1
" for ::1 at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/pages-8450695447adc4c25ef72b73f84e12b5.css?body=1" for ::1
at 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:15] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/show-bd6702d041298d2548881c1db5e4e9a7.css?body=1" for ::1 a
t 2015-02-24 22:40:15 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/viewings-64e62ddc273c2f5847f30d698ca14b67.css?body=1" for :
:1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/moment-66988874bf5714cb1e4a6f53d733b6e1.js?body=1" for ::1
at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/jquery-87424c3c19e96d4fb033c10ebe21ec40.js?body=1" for ::1
at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] 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-e27bd20a10d28155845a22d71ef94f2f.js?body=1" for
::1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/turbolinks-da8ddad9c2c5483d4c5c30c1ce325253.js?body=1" for
::1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/fullcalendar-f09a2cee6bd3f7655c47cf7eab2b52b9.js?body=1" fo
r ::1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/owl.carousel.min-7972660fd0b56886b322fbde7ad2f1f7.js?body=1
" for ::1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/pages-fcec5b5a277ac7c20cc9f45a209a3bcd.js?body=1" for ::1 a
t 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/rmcats-fcec5b5a277ac7c20cc9f45a209a3bcd.js?body=1" for ::1
at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/rooms-fcec5b5a277ac7c20cc9f45a209a3bcd.js?body=1" for ::1 a
t 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/viewings-fcec5b5a277ac7c20cc9f45a209a3bcd.js?body=1" for ::
1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/assets/application-5fac6df9a34c6823e27885b0701b0037.js?body=1" for
::1 at 2015-02-24 22:40:16 +0000
[2015-02-24 22:40:16] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
Started GET "/viewings?start=2015-02-22&end=2015-03-01&_=1424817616261" for ::1
at 2015-02-24 22:40:17 +0000
Processing by ViewingsController#index as JSON
Parameters: {"start"=>"2015-02-22", "end"=>"2015-03-01", "_"=>"1424817616261"}
←[1m←[35mViewing Load (1.0ms)←[0m SELECT "viewings".* FROM "viewings"
Rendered viewings/index.json.jbuilder (30.1ms)
Completed 200 OK in 65ms (Views: 59.3ms | ActiveRecord: 1.0ms)
I'm not sure what all those "Could not determine content-length of response body" messages are, but I think the last 3 lines above seem to be whats causing it to show all viewings in the calendar.
You probably need to tie the search function to calling the calendar function in events.js.coffee:
$(document).ready ->
$("#calendar").fullCalendar(
events: '/events.json'
)
Not sure how to do this, but you want to trigger this function after each search, because you are getting the correctly filtered list but the calendar is not reloading with the current list of events.
I'm starting to think maybe you would be better off just having a main calendar that shows everything, and instead of a search function, use a dropdown menu of links that has every room listed. You could then just nest your routes:
in config/routes.rb
...
resources rooms do
resources events
end
That way your links to each room would go to that room's calendar in a route like
localhost:3000/room1/events
since Events already belong to rooms. In your rooms controller you can have the #show action use the room id to find the events:
def show
#room_events = Room.where(id: room_params[:id]).events
end
Then in /views/rooms/show you would put the calendar code.
The dropdown for choosing rooms would be built on the fly from a query
#rooms = Room.all
and then just use a dropdown menu in .erb to get the links for each room.
EDIT:
I am not familiar with jbuilder, so my answer may not be any help. Is your intention to update the index page after it has already loaded once?
I still think your problem is that you are defining the variable #viewings twice, once in the partial and once in the index. The last call is to index so that is the final value when it displays.
Ok, so looking at the code for your calendar:
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
events: '/viewings.json',
defaultView: 'agendaWeek',
slotMinutes: 60,
})
});
I'm wondering if this is where your issue is, maybe you need to load the updated events from /viewings.json. So either use AJAX to request the filtered events query, then update the calendar from an .js.erb partial and an .html.erb partial? If the calendar is based on a table and you are using Jquery you could use the filter functions built into Jquery.
Or...
You could use CSS. I'm not good at CSS but I'm pretty sure you could set all the events as visible and use the search function as a filter to change the visibility of everything to invisible except for the ones that go to the room you are filtering for.
This is a stab in the dark with the limited info to go on but try changing your instance variable for the room-limited viewings from
#viewings
to something like:
#room_viewings
That way you are not stomping on it when you call
render index

Rails Devise sessions inadvertently destroyed in production mode

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

"New" render redirects to unexpected URL

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.

Is there something wrong with my link_to?

<%= 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.

Resources