I'm following: The infamous RoR blog tutorial security section
And from some odd reason when trying to reach the specific relevant page i'm getting a:
undefined method 'http_basic_authenticate_with' for PostsController:Class
error
I'm using:
Any idea what might cause this or maybe a specific gem which is missing?
part of the controller code:
class PostsController < ApplicationController
http_basic_authenticate_with :name => "dhh", :password => "secret",
:except => :index
# GET /posts
# GET /posts.xml
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
format.json { render :json => @posts }
end
end
I think this method is only available to Rails 3.1
now, looking at the release notes:
http://guides.rubyonrails.org/3_1_release_notes.html#action-controller
Also the guide says:
This Guide is based on Rails 3.1. Some of the code shown here will not work in earlier versions of Rails.
You can try this for rails version 3 and earlier:
class ApplicationController < ActionController::Base
USER, PASSWORD = 'dhh', 'secret'
before_filter :authentication_check, :except => :index
...
private
def authentication_check
authenticate_or_request_with_http_basic do |user, password|
user == USER && password == PASSWORD
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With