Reputation: 1617
I have an app that allows users to create profiles and I'd like them to be able to update their profiles in the profile view rather than going to the edit page. Here's an example from OkCupid:
https://i.sstatic.net/5QX39.jpg
This can be done using the bootstrap-x-editable-rails gem, but I'd like to know if I have to create a database column for each question? Or if I can somehow just use one - I guess the question is how can I achieve something like the example above in rails?
Thanks in advanced!
Upvotes: 2
Views: 231
Reputation: 24815
Each column(field) for each question is a bad idea.
What if you want to add question? Add another field? What if you want to change question? Also how to define the name of the fields? Wouldn't you need a hash in model to translate them into real question? What if you decide to allow user to add their own question?
A better approach is to define a Question model.
The basic idea is, this model belongs to User, so it's possible to let every user add their own questions later. Initially, you can set basic questions belongs to a certain admin or better with an attribute public: true
, and every user can see this kind of questions
Then, user also has Answer model. Each answer belongs to a certain question. That's intuitive.
Then, done.
Upvotes: 3