I'm having trouble discerning why my app is returning a 401 Unauthorized. Other actions in my Institutions controller are working just fine while not signed in. However, this and another page are returning 401. If logged in, these pages work perfectly fine, but they shouldn't require being logged in. I have even gone so far as to empty the view and the action, but still the page is returning a 401. When debugging through fiddler, I simply receive a 302 Redirect.
I've tried researching elsewhere and have tried the solutions from Warden authentication recalls 401 Unauthorized without success.
Console
Started GET "/institutions/3" for 127.0.0.1 at 2013-04-25 14:38:15 -0400
Processing by InstitutionsController#show as HTML
Parameters: {"id"=>"3"}
←[1m←[36mInstitution Load (0.0ms)←[0m ←[1mSELECT `institutions`.* FROM `institutions` WHERE `institutions`.`id` = 3 LIMIT 1←[0m
Load data...
Load assets...
Then I submit the form, method is set as GET
Started GET "/visit/schedule/preview?utf8=%E2%9C%93&selected_ids=4693" for 127.0.0.1 at 2013
-04-25 14:28:53 -0400
Processing by InstitutionsController#previewselectedvisits as HTML
Parameters: {"utf8"=>"√", "selected_ids"=>"4693"}
Completed 401 Unauthorized in 0ms
Started GET "/users/sign_in" for 127.0.0.1 at 2013-04-25 14:28:53 -0400
Processing by Devise::SessionsController#new as HTML
Rendered devise/sessions/new.html.erb within layouts/application (15.6ms)
Rendered auth/_login.html.erb (0.0ms)
Rendered auth/_loginmodal.html.erb (0.0ms)
Rendered shared/_navbarout.html.erb (0.0ms)
Rendered shared/_navbar.html.erb (0.0ms)
←[1m←[36mInstitution Load (0.0ms)←[0m ←[1mSELECT name FROM `institutions` ←[0m
Rendered search/_searchbar.html.erb (0.0ms)
Rendered search/_searchresults.html.erb (0.0ms)
Rendered shared/_footer.html.erb (0.0ms)
Completed 200 OK in 140ms (Views: 46.8ms | ActiveRecord: 15.6ms)
Load assets...
Relevant Routes
devise_for :users
match 'visit/schedule/preview' => 'institutions#previewselectedvisits', :as => :preview_visits, :via => :get
match "institutions/:id" => "institutions#show", :as => :show_institution
rake routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise_invitable/registrations#cancel
user_registration POST /users(.:format) devise_invitable/registrations#create
new_user_registration GET /users/sign_up(.:format) devise_invitable/registrations#new
edit_user_registration GET /users/edit(.:format) devise_invitable/registrations#edit
PUT /users(.:format) devise_invitable/registrations#update
DELETE /users(.:format) devise_invitable/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
user_unlock POST /users/unlock(.:format) devise/unlocks#create
new_user_unlock GET /users/unlock/new(.:format) devise/unlocks#new
GET /users/unlock(.:format) devise/unlocks#show
accept_user_invitation GET /users/invitation/accept(.:format) devise/invitations#edit
remove_user_invitation GET /users/invitation/remove(.:format) devise/invitations#destroy
user_invitation POST /users/invitation(.:format) devise/invitations#create
new_user_invitation GET /users/invitation/new(.:format) devise/invitations#new
PUT /users/invitation(.:format) devise/invitations#update
preview_visits GET /visit/schedule/preview(.:format) institutions#previewselectedvisits
show_institution /institutions/:id(.:format) institutions#show
vote_institution /institutions/:id/vote/:visittype_id(.:format) institutions#vote
/institutions/:id/:offset(.:format) institutions#show
institutions /institutions(.:format) institutions#index
schedule_visits /schedule(.:format) institutions#index
auth_failure /auth/failure(.:format) services#failure
/auth/:service/:callback(.:format) services#create
services GET /services(.:format) services#index
POST /services(.:format) services#create
service DELETE /services/:id(.:format) services#destroy
login_user /users/login(.:format) users#login
myvisits_user /users/myvisits(.:format) users#myvisits
email_myvisits_user /users/myvisits/email(.:format) users#emailmyvisits
remove_visit_from_user /users/removevisit/:id/:user_id(.:format) users#rmvisit
addvisits_user /users/addvisits(.:format) users#addvisits
changevisit_user /users/visits/:user_id/:visit_id/:is_going(.:format) users#toggle_user_going_on_visit
add_family_to_user /users/invite(.:format) users#addfamilymember
add_family_default_to_user /users/profile/addfamilymemberdefault(.:format) users#addfamilymember_default
remove_family_from_user /users/profile/removefamilymember(.:format) users#rmfamilymember
update_profile_user /users/profile/update(.:format) users#update
update_profile_other_user /users/profile/update/:id(.:format) users#update
edit_profile_user /users/profile/edit(.:format) users#edit
show_profile_user /users/profile(.:format) users#show
users /users(.:format) users#show
families GET /families(.:format) families#index
POST /families(.:format) families#create
new_family GET /families/new(.:format) families#new
edit_family GET /families/:id/edit(.:format) families#edit
family GET /families/:id(.:format) families#show
PUT /families/:id(.:format) families#update
DELETE /families/:id(.:format) families#destroy
visits /visits(.:format) visits#index
company /company(.:format) company#aboutus
edu /edu(.:format) edu#index
root / institutions#index
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'mysql2'
gem 'execjs'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'simple_form'
gem 'devise'
gem 'devise_invitable'
gem 'omniauth'
gem "omniauth-google-oauth2"
gem 'omniauth-linkedin-oauth2'
gem 'omniauth-facebook'
#in-place editing
gem 'best_in_place'
#email template convert to inline
gem 'roadie'
#amazon web services and images
gem 'paperclip'
gem 'aws-sdk'
check the code of your InstitutionsController and ApplicationController -- look for statements with current_user or before_filter in them
class InstitutionsController < ApplicationController
before_filter :login_required, :only => [:method1,:method2]
...
end
could be that the method you are trying to call is listed as requiring authentication, but you are not logged in.
Can you also post an excerpt of your InstitutionsController with the preview method in it?
Another possible problem is that your route might be defined incorrectly:
match 'visit/schedule/preview' => 'institutions#previewselectedvisits', :as => :preview_visits, :via => :get
does the InstitutionsController really have a method called previewselectedvisits ?
Related
I want to use guard to run my bacon tests, my Gemfile looks like:
source 'https://rubygems.org'
gem 'sinatra'
gem 'sidekiq'
gem 'slim'
gem 'puma'
gem 'nokogiri'
gem 'httparty'
group :test, :development do
gem 'guard'
gem 'bacon'
gem 'guard-bacon'
gem 'libnotify'
gem 'rb-inotify'
end
My Guardfile looks like
# parameters:
# output => the formatted to use
# backtrace => number of lines, nil = everything
guard 'bacon', :output => "BetterOutput", :backtrace => 4 do
watch(%r{^lib/(.+)\.rb$}) { |m| "specs/lib/#{m[1]}_spec.rb" }
watch(%r{specs/.+\.rb$})
end
When I run guard the following happens
$ guard
Bacon: Using output BetterOutput.
Bacon: Limiting backtrace to 4 lines.
09:02:05 - INFO - Guard uses Libnotify to send notifications.
09:02:05 - INFO - Guard uses TerminalTitle to send notifications.
09:02:05 - INFO - Guard is now watching at '/home/martin/code/jse-api'
Guard::Bacon started.
[1] guard(main)> %
$
It seems to load everything, get to the guard prompt and exit.
I have no idea why?
The issue seems to the version of guard required by guard-bacon 1.1.0
If you force it to the latest version of guard
gem 'guard', '>= 1.8.0'
It falls back to a older version of guard-bacon 1.0.5 and everything works.
I'm trying to deploy a simple skeleton Rails 3.0.5 (and Ruby 1.9.2) app to Heroku, but encounter the same error when I open the website and when I try to migrate the db. I created the Heroku app with heroku create --stack bamboo-mri-1.9.2. Everything works locally.
Code: https://github.com/curiousyogurt/SEE
App: http://stormy-ice-778.heroku.com/
When going to the website, I get an "Application Error"; in the logs, I get the following error (followed by lots of other information):
2011-03-20T17:25:31-07:00 app[web.1]: /app/cfde9dd3-c394-45fb-a0ef-72a753e83909/home/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/railtie/configuration.rb:77:in 'method_missing': undefined method `action' for #<Rails::Application::Configuration:0x00000001d398d8> (NoMethodError)
Stack Trace: gist.github.com/878866
When doing heroku rake db:migrate, I get the following error:
rake aborted!
undefined method 'action' for #
/app/44666f97-ad08-444e-9f39-9ca7eb8fdc93/home/.bundle/gems/ruby/1.9.1/gems/railties-3.0.5/lib/rails/railtie/configuration.rb:77:in `method_missing'
Stack Trace: gist.github.com/878870
Here is my Gemfile (non-production parts removed):
gem 'rails', '3.0.5'
gem 'haml'
gem 'devise', :git => 'git://github.com/plataformatec/devise',
:branch => 'master'
gem 'omniauth'
I'm not sure where to go next in trying to track down this problem. Any suggestions would be greatly appreciated.
config.action.mailer.default_url_options = { :host => 'stormy-ice-778.heroku.com' }
in your config/environments/production.rb should be
config.action_mailer.default_url_options = { :host => 'stormy-ice-778.heroku.com' }
(change action.mailer to action_mailer).
Same question, but solution did not work:, I've tried several versions of rspec:
Why is Rspec saying "Failure/Error: Unable to find matching line from backtrace"?
dpalacio:sample_app dpalacio$ rspec -v
2.0.0.beta.18
dpalacio:sample_app dpalacio$ rspec spec/
controllers/ factories.rb models/ requests/ spec_helper.rb
dpalacio:sample_app dpalacio$ rspec spec/requests/
FFFFF
Finished in 0.55501 seconds
5 examples, 5 failures
1) LayoutLinks should have a Home page at '/'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
2) LayoutLinks should have a Contact page at '/contact'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
3) LayoutLinks should have an About page at '/about'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
4) LayoutLinks should have a Help page at '/help'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
5) LayoutLinks should have a Help page at '/signup'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
And the same with the 2.0.1 version:
dpalacio:sample_app dpalacio$ rspec -v
2.0.1
dpalacio:sample_app dpalacio$ rspec spec/
controllers/ factories.rb models/ requests/ spec_helper.rb
dpalacio:sample_app dpalacio$ rspec spec/requests/
FFFFF
Finished in 0.55501 seconds
5 examples, 5 failures
1) LayoutLinks should have a Home page at '/'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
2) LayoutLinks should have a Contact page at '/contact'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
3) LayoutLinks should have an About page at '/about'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
4) LayoutLinks should have a Help page at '/help'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
5) LayoutLinks should have a Help page at '/signup'
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /Users/dpalacio/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/forwardable.rb:185
Ok found the issue, the issue is not RSPEC but WEBRAT.
Add to your Gemfile:
gem 'webrat', '0.7.1'
The version of RSPEC should be:
gem 'rspec', '2.0.1'
It's hard to see this as a (purely) webrat issue ...
group :test, :development do
gem 'rspec-rails', '2.0.0.beta.18'
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber'
gem 'spork'
gem 'launchy'
end
... since I'm using capybara instead of webrat.
Any ideas are welcome.
This doesn't seem to be an issue as of rspec 2.2.0
gem 'rails', '3.0.0'
gem 'devise'
gem 'bson_ext', '>= 1.0.7'
gem 'bson', '>= 1.0.7'
gem 'mongo_mapper', :branch => 'rails3', :git => 'http://github.com/jnunemaker/mongomapper.git'
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
With the above setup I get the following errors on requests:
Started GET "/users/sign_out" for 127.0.0.1 at 2010-09-27 13:16:30 +0300
Processing by Devise::SessionsController#destroy as HTML
Redirected to http://localhost:3000/
Completed 302 Found in 19ms
[2010-09-27 13:16:31] ERROR Errno::ECONNRESET: Connection reset by peer
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/usr/local/ruby/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Started GET "/users/edit" for 127.0.0.1 at 2010-09-27 13:16:35 +0300
Processing by Devise::RegistrationsController#edit as HTML
Completed in 16ms
[2010-09-27 13:16:35] ERROR Errno::ECONNRESET: Connection reset by peer
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/usr/local/ruby/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
The user model:
class User
include MongoMapper::Document
plugin MongoMapper::Devise
devise :registerable, :database_authenticatable, :recoverable
end
Ideas?
WebRick has been replaced with Thin.
Doing the following worked for me:
Gemfile:
gem 'thin'
Now do bundle install
My quick guess is this looks like you have a problem with your sessions and protect_from_forgery is kicking in.
I had a similar problem and smashed my head against the wall for a few days, it turned out to be I was assigning an entire object to a session object instead of just the id. A quick note, non-GET requests are the ones that trigger the protect_from_forgery.
Adding this to my development.rb file fixed the issue.
config.assets.raise_runtime_errors = true
config.web_console.whitelisted_ips = replace_this_with_the_public_ip
When i run my features i get this error:
undefined method `visit' for #<Cucumber::Rails::World:0x81b17ac0> (NoMethodError)
This is the relevant part of my Gemfile.
group :development, :test do
gem "rspec-rails", ">= 2.0.0.beta.19"
gem "cucumber"
gem "cucumber-rails", ">= 0.3.2"
gem 'webrat', ">= 0.7.2.beta.1"
end
The relating step_definition (though i don't think it's important)
When /^I create a movie Caddyshack in the Comendy genre$/ do
visit movies_path
click_link "Add Movie"
fill_in "Title", :with => "Caddyshack"
check "Comedy"
click_button "Save"
end
In the env.rb i have the following Webrat configuration:
# […]
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]
Anything i am missing here?
I had to set config.mode to :rack instead of :rails:
# […]
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
# […]
now works as expected.
Paul Nelligan try adding this to env.rb to fix the error : "no such file to load -- action_controller/integration"
World(Webrat::Methods)
World(Webrat::Matchers)
I also encountered this error on two separate occasions: the first instance the adjustment to confg.mode solved the problem; the second time, however, after a lot of frustration I found a link that suggested a buggy version of bundler could be the culprit. Updating it solved the problem.