Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ========== Example of problem ==========
- @user = User.create(gid: foo, permissions: bar)
- @gapiToken = @user.gapiToken.create(access_token: foo, token_type: bar, expires_on: bazz, refresh_token: bop)
- #^ Error ^ "undefined method `create' for nil:NilClass"
- ========== Models ==========
- #./app/models/user.rb
- class User < ActiveRecord::Base
- has_many :userSessions
- has_one :gapiToken
- end
- #./app/models/user_session.rb
- class UserSession < ActiveRecord::Base
- belongs_to :user
- end
- #./app/models/gapi_token.rb
- class GapiToken < ActiveRecord::Base
- belongs_to :user
- end
- ========== Migrations ==========
- #./db/migrate/xxxxxx_create_users.rb
- class CreateUsers < ActiveRecord::Migration
- def change
- create_table :users do |t|
- t.string :gid
- t.string :permissions
- t.timestamps
- end
- end
- end
- #./db/migrate/xxxxxx_create_user_sessions.rb
- class CreateUserSessions < ActiveRecord::Migration
- def change
- create_table :user_sessions do |t|
- t.belongs_to :user
- t.string :sid
- t.string :secret
- t.datetime :expires_on
- t.timestamps
- end
- end
- end
- #./db/migrate/xxxxxx_create_gapi_tokens.rb
- class CreateGapiTokens < ActiveRecord::Migration
- def change
- create_table :gapi_tokens do |t|
- t.belongs_to :user
- t.string :access_token
- t.string :token_type
- t.datetime :expires_on
- t.string :refresh_token
- t.timestamps
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement