Rails3 RegexpError (regular expression too big: /password|password_confirmation) - ruby

I'm using Rails 3.0.0 with Authlogic 2.1.6 and from time to time I'm getting this error message:
RegexpError (regular expression too big:
/password|password_confirmation....
It results with internal server error and I have to restart my server to get it work again. Anyone know how to avoid this issue?

It's sounding as though the :length of the password and/or password_confirmation fields is too long. Do a validation first: validates_length_of :password … to keep too large of passwords from being entered.

Related

"CSRF detected" with Omniauth and Google

I'm getting this
OmniAuth::Strategies::OAuth2::CallbackError at /auth/google/callback
csrf_detected | CSRF detected
My code:
require 'sinatra'
require "sinatra/json"
require "sinatra/config_file"
require 'omniauth-oauth2'
require 'omniauth-google-oauth2'
use Rack::Logger
config_file "config/app_config.yml"
use Rack::Session::Cookie, secret: '5fb7w345y3489f523y4h'
configure do
enable :sessions
end
use OmniAuth::Builder do
provider :google_oauth2, settings.google[:client_id], settings.google[:secret],
{
:scope => "userinfo.profile",
:access_type => "offline",
:prompt => "select_account consent",
:name => "google"
}
end
get '/list' do
json get_list
end
get '/' do
%Q|<a href='/auth/google'>Sign in with Google</a>|
end
get '/auth/:name/callback' do
#auth = request.env['omniauth.auth']
#auth.inspect
end
My callback is returning both code and state.
This problem occurs with rails when the domain defined in /config/initializer/session_store.rb is different from the origin/redirect_uri defined in the google api console.
MyApp::Application.config.session_store :cookie_store, key: '_app_session', domain: 'my_app.com'
Removing the domain params or using the same domain on both sides fixed the problem.
If you are using Devise with OmniAuth you need to skip the extra omniauth.rb initializer file and simply add config.provider "KEY", "SECRET" inside your initializers/devise.rb and then carry on with your implementation.
Got the same problem
(google_oauth2) Callback phase initiated.
(google_oauth2)
Authentication failure! csrf_detected:
OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF
detected
Last Omniauth-oauth2 update introduced the "state" param has a mandatory field.
Some people suggest using provider_ignores_state: true but it's a bad idea because it introduces csrf flaw
Guess we'll have to downgrade to previous version to keep google_oauth2 working.
Issue it on https://github.com/intridea/omniauth-oauth2/issues/58
Are you hitting back and reattempting to log in? I was getting this issue and it was really confusing me, but it was because I was going back to retry. If I typed in the address again, I wouldn't get the issue

CouchDB: weird query_parse_error with curl, not with Ruby

I'm hosting my Couch instance on iriscouch.com and doing some testing with a simple Sinatra app, using CouchRest Model.
Here's a simple model I'm using:
class User < CouchRest::Model::Base
property :first_name, String
property :last_name, String
timestamps!
design do
view :by_first_name
end
end
I'm successfully creating new users with:
User.create(:first_name => "Stonewall", :last_name => "Jackson")
Executing User.by_first_name.all results in this HTTP request:
http://test_admin:pwd#testytest.iriscouch.com:80/blt/_design/User/_view/by_first_name?include_docs=true&reduce=false
"Accept"=>"application/json"
"Accept-Encoding"=>"gzip, deflate"
"Content-Type"=>"application/json"
This is executed by RestClient, via CouchRest. No problems there.
But when I try to curlthis URL, I get complaints from Couch about the include_docs parameter:
{"error":"query_parse_error","reason":"Query parameter `include_docs` is invalid for reduce views."}
I'd like to understand what's going on here. Why is include_docsa problem only when using curl?
One difference is that your URL now contains a question mark. If you don't protect the URL in the shell, it will be interpreted as a special character.
If you want a simpler way to test your services, you can use RESTClient instead of curl.

Why can't I check ActiveRecord validations in the console?

I'm learning RoR at the moment, and I think I must be misunderstanding something.
I have an ActiveRecord class call User, with simple validations on :name and :email such as presence: true, length: { maximum: 15 }, etc. I thought I'd check the validations in the console. I go into rails console (development env), and create a new instance with a name that is too long, such as
user_instance = User.new (name:"aaaaabbbbbcccccddddd", email:"").
The validation doesn't throw up any errors. When I try user_instance.save, the record won't write to the DB, so it's obviously working fine at that stage. What am I doing wrong?
When you want to get an exception raised on record saving, use save! instead of save (same with update/update!, create/create!).
With save you won't have an exception raised if there are validation errors, it will just return false. You can also check if there are errors on an instance with user_instance.valid? and get the errors with user_instance.errors.
See When Does Validation Happen?.
the validation won't throw errors if you try to set invalid data on your model, however the save will fail.
if you wanna check out if the validation is working correctly, just check user.valid? and it should return false
after calling valid?, you can check user.errors for the specific errors set on your model.

Rails model validation not working

model:
validates :name, :presence => true
validates :year, :presence => true
validates :description, :presence => true
when submitting the form containing these fields, leaving the text boxes blank on purpose, instead of getting the Rails error messaging, I get the following exception thrown:
NoMethodError
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Any thoughts on why this may occur would be greatly appreciated.
A stab in the dark would be that its not your validations throwing the error message. My first instinct is that its the error view code (if you are looping through the errors the nil is possibly in there). Its also possible its an error in the controller but I would have to see the first couple lines of the backtrace to make a more informed guess.

undefined local variable or method 'within' for User:class

I am working with a book to teach myself Ruby-on-Rails. Ruby version is 1.2.3 and rubygems V 1.3.5.
I start the console by ruby script/console and enter:
user = User.new(:screen_name => "example",
?> :email => "exampleATexample.com",
?> :password => "example")
but instead of adding the data to the DB, I get the following:
NameError: undefined local variable or method 'within' for User:Class from D:/ruby/lib/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1235:in 'method_missing' from ./script/../config/../config/../app/modules/user.rb:13
I don't really understand what's going on. Any kind of help is much appreciated, thank you!
First, I believe you main Rails v 1.2.3, this is a very old version of Rails, don't use it.
Second thing, the command you entered has wrong Ruby syntax... try this instead:
user =User.new(:screen_name => "example", :email => "exampleATexample.com", :password => "example")
Third thing: please paste more code....
Also, just as a check.
Whenever something doesn't work in Rails that has to do with the database, make sure you run
rake db:migrate
Sometimes this can slip your mind and cause weird errors.
Also, just as a side note... I would make sure that you add some validations to your user model that requires a user to confirm their password and or email. It's generally a good practice.
validates_confirmation_of :password, :email
All the best with learning Rails. Make sure you take #dvyjones's advice and upgrade to the latest version of Rails... a lot has changed since v. 1.2.3

Resources