Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.find_by_alias() generates invalid Ruby code #13261

Closed
sunaku opened this issue Dec 10, 2013 · 0 comments · Fixed by #13264
Closed

Model.find_by_alias() generates invalid Ruby code #13261

sunaku opened this issue Dec 10, 2013 · 0 comments · Fixed by #13264

Comments

@sunaku
Copy link
Contributor

sunaku commented Dec 10, 2013

Column names should be sanitized (e.g. by appending an underscore) before they are used as Ruby variable names in generated find_by_* method bodies so that they don't get misinterpreted as Ruby keywords:

>> User.find_by_alias("chuck")
SyntaxError: /home/skurapati/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:65: syntax error, unexpected keyword_alias, expecting ')'
          def self.find_by_alias(alias, options = {})
                                      ^
/home/skurapati/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:65: syntax error, unexpected ')', expecting end-of-input
        from /home/skurapati/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:64:in `class_eval'
        from /home/skurapati/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:64:in `define'
        from /home/skurapati/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:19:in `method_missing'

Thanks for your consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants