bouchard / thumbs_up

Dead-Simple Vote and Karma Management
MIT License
412 stars 75 forks source link

Rails 4 Compatibility #83

Closed andoneve closed 9 years ago

andoneve commented 11 years ago

I am trying to use thumbs_up with Rails 4. I have added and run the migrations. I have my voteable and voter setup correctly. But when I do something like this:

2.0.0-p195 :003 > v = Vote.new(:vote => :up, :voteable => idea, :voter => nicole)
DEPRECATION WARNING: Using #scope without passing a callable object is deprecated. For example `scope :red, where(color: 'red')` should be changed to `scope :red, -> { where(color: 'red') }`. There are numerous gotchas in the former usage and it makes the implementation more complicated and buggy. (If you prefer, you can just define a class method named `self.red`.). (called from <class:Vote> at /Users/laurawadden/summer_of_code/freddit/app/models/vote.rb:20)

 => #<Vote id: nil, vote: false, voteable_id: nil, voteable_type: nil, voter_id: nil, voter_type: nil, created_at: nil, updated_at: nil> 

2.0.0-p195 :004 > v.save

And I get this error:

Please help! Thanks.

SQLite3::ConstraintException: constraint failed: INSERT INTO "votes" ("created_at", "updated_at") VALUES (?, ?)
   (0.2ms)  rollback transaction
ActiveRecord::StatementInvalid: SQLite3::ConstraintException: constraint failed: INSERT INTO "votes" ("created_at", "updated_at") VALUES (?, ?)
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `step'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `block in each'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `loop'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `each'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/sqlite3_adapter.rb:313:in `to_a'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/sqlite3_adapter.rb:313:in `block in exec_query'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activesupport-4.0.0.rc1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/sqlite3_adapter.rb:292:in `exec_query'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:69:in `exec_insert'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `insert'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/relation.rb:76:in `insert'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/persistence.rb:456:in `create_record'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/attribute_methods/dirty.rb:78:in `create_record'
... 13 levels...
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:270:in `block (2 levels) in save'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:209:in `transaction'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:270:in `block in save'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/activerecord-4.0.0.rc1/lib/active_record/transactions.rb:269:in `save'
    from (irb):4
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands/console.rb:90:in `start'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/rvm/gems/ruby-2.0.0-p195@railstutorial_rails_4_0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:66:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'2.0.0-p195 :005 > 
bouchard commented 11 years ago

Hello @queenfrankie, happy to fix thumbs_up for Rails 4 if necessary. I notice you're running Rails 4 RC1, could please try with the final version of Rails 4? And if that error still exists, seeing your vote.rb file would be great - the current vote.rb migration file includes lambdas in the definition of scopes, so we shouldn't be seeing those errors. As for your SQLite error, can you please let me know what you were doing that caused that error? Thanks.

andoneve commented 11 years ago

It is working now! Thanks for the ideas.

L

On Thu, Jun 27, 2013 at 5:05 PM, Brady Bouchard notifications@github.comwrote:

Hello @queenfrankie https://github.com/queenfrankie, happy to fix thumbs_up for Rails 4 if necessary. I notice you're running Rails 4 RC1, could please try with the final version of Rails 4? And if that error still exists, seeing your vote.rb file would be great - the current vote.rb migration file includes lambdas in the definition of scopes, so we shouldn't be seeing those errors. As for your SQLite error, can you please let me know what you were doing that caused that error? Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/bouchard/thumbs_up/issues/83#issuecomment-20125952 .

laura pierson wadden +49 0176 8773 3595 | facebook.com/lpwadden

myKingEdem commented 10 years ago

:+1:

gregmolnar commented 9 years ago

This and #100 can be closed as the master branch works with rails 4.2. Any plan to do a release?

bouchard commented 9 years ago

Released!

gregmolnar commented 9 years ago

Thank you!

dana007 commented 7 years ago

I installed thumbs_up gem, but when I tried to run 'rails g thumbs_up', I get the following error:
image

I googled it but I cannot find a solution.

I tried with both spellings - rails g thumbs_up and rails g thumb_up. The screenshot shows one with a singular thumb_up.

gregmolnar commented 7 years ago

@dana007 Could you please let me know the version of Rails you are using?

dana007 commented 7 years ago

image

bouchard commented 7 years ago

Hey @dana007, from your screenshot above, it looks like you misspelled the generator "thumbs_up", not "thumb_up".

dana007 commented 7 years ago

Actually, I tried both spelling and I happened to post just one. Sorry about that.

On Wed, Nov 30, 2016 at 11:04 AM, Brady Bouchard notifications@github.com wrote:

Hey @dana007 https://github.com/dana007, from your screenshot above, it looks like you misspelled the generator "thumbs_up", not "thumb_up".

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bouchard/thumbs_up/issues/83#issuecomment-263913117, or mute the thread https://github.com/notifications/unsubscribe-auth/AQEqHlz3d6FQdcJM8Gy5JKujaILwCBLRks5rDZ5-gaJpZM4AxXbU .

dana007 commented 7 years ago

I edited my comment on GitHub that I had tried both spellings.

On Wed, Nov 30, 2016 at 11:24 AM, Dana Turner peppoya@gmail.com wrote:

Actually, I tried both spelling and I happened to post just one.

On Wed, Nov 30, 2016 at 11:04 AM, Brady Bouchard <notifications@github.com

wrote:

Hey @dana007 https://github.com/dana007, from your screenshot above, it looks like you misspelled the generator "thumbs_up", not "thumb_up".

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bouchard/thumbs_up/issues/83#issuecomment-263913117, or mute the thread https://github.com/notifications/unsubscribe-auth/AQEqHlz3d6FQdcJM8Gy5JKujaILwCBLRks5rDZ5-gaJpZM4AxXbU .