Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Database --> User Profile --> Rating --> Database?


  • Please log in to reply
1 reply to this topic

#1 eto

eto

    Passenger

  • Members
  • 2 posts

Posted 07 January 2014 - 01:54 AM

Hello there!

 

I am creating a Rails app wherein there is a Database of Books.

 

I want my Users to sign in, see the "Master" list of books, and then check off books to add to their "To read" list.

 

These books will then appear on their User Profile page on their "To read" list.

 

The User can check off the books they've completed, and these books will then be marked "Read".

 

So far I have working sign-in with Devise, which redirects a sign-in user to a very large Master list of books.

 

Any advice on where to go next? Any good tutorials or something for this? I am finding a lot of tutorials on creating blogs and "facebook" type apps, but none on simple "To do" apps that pull from an existent database.

 

I guess what I am most confused by is the Models and Associations.

 

Should my Users have_many: books ...?

Should my Books  belongs_to: users or user ???

 

Thank you in advance, friends.

 

I'm also willing to show my code to anyone who really wants to help out. It's on Github. Just PM me.



#2 RoyTheB0y

RoyTheB0y

    Signalman

  • Members
  • 10 posts

Posted 09 January 2014 - 09:35 PM

I don't think you want Books to belong_to User as this would store a user_id in the book record and presumably many users can have read the same book which this approach would preclude.

 

check out http://guides.rubyon...ion_basics.html

 

Off the top of my head,, but bear in mind I'm a newbie here too

 
class Users < ActiveRecord::Base
  has_many :read_books
  has_many :books, through: :read_books
end
 
class ReadBooks < ActiveRecord::Base
  belongs_to :user
  belongs_to :book
end
 
class Book < ActiveRecord::Base
  has_many :read_books
  has_many :users_who_read_me, through: :read_books
end

  • james likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users