Dynamic forms and models in rails [closed] - ruby-on-rails

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have been trying to figure out how eBay would create their forms in rails. (FYI I know that they don't use rails). So far I have come to the conclusion that their could be two models
Posts "<- would contain the basics every post contains"
-
Post_id
User_id
Category_id
Photos
Title
condition
Location
Price
This is pretty simple, but lets say a user wants to sell a car, the form would ask them for the mileage, model, year etc. But in contrast, if a user wants to sell a table, the form would not ask for the information it would generally ask for a car. Is their a way to accomplish this is rails without having to create many models and associating them with Posts?

I guess the simplest scenario would be thus:
"Category has a name" (this will keep "car", "bird", "soul", whatever they sell on e-bay)
"Property is made of a name, a value and a category"
"Product has many Properties"
Each product will have N properties belonging to a certain category.
Use-case (new category):
When you create a new category, you can create properties belonging to it, or add properties from existing other categories (composition)
Use-case (new product):
When you want to create a new product, you select a category and properties belonging to that category will be added dynamically to your product.

Related

Best way to create a FAQ section in Rails [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have 300 questions and answers and each of the questions fall in one of four categories. My question is what would be the best way to create web searchable pages for each 300 Q&A.
My first thought is to just do it simple and create one model. The one model will have question:string answer:text category:string and then input all the questions and answers in the database.
My second choice would be to create a category model and then a model for questions and answers.
My third choice is to create a JSON file with the questions and answers formatted then call on it through Javascript.
What would be the best way to achieve this while allowing search engines to rank each question?
I would say, go with single model Faq which contains all the required info i.e. question, answer, and category.
You don't need a separate model for categories if:
The categories list is predefined (in which case you can use enum type field), AND
Each category has only a name and no other attributes.
About JSON file, it will be difficult to add/remove FAQs in that. You will probably need to push your code after every change. With a model Faq in application, you can always do CRUD on FAQs easily.
So, the final structure should be like this:
class Faq
# field :question
# field :answer
# field :category, type: :enum, values: %w[<category-names>]
end
And for rendering FAQs category-wise, you can always group on category.

Coredata chained Relationship [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
What is the best way to update or add data if relationships are chained.
I have my coredata designed like this:
I have 3 Entities
1) User To_Many Category
2) Category To_Many Item
3) Item To_One Category
User is required before adding a Category, and Category is required before adding an Item
Simple. Just set the to-one relationship, the corresponding inverse relationship will be set automatically by Core Data.
newItem.category = category
category.user = user
According to best practice, I am renaming the clumsy attribute names itemCategory, categoryUser, categoryInUser to simply category, user, categories respectively.

Best practice for Like feature in social network app with ParseDB [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm need to add new 'Like' feature to existing Social Network iOS app.
The user can do 'Like' action on comments of other users.
1) If the the user hits 'Like' the comment will be marked as 'Liked' by the user.
2) I need to display the 'Likes' count in the comment view.
3) If the user hits the count of the 'Likes' he can see the list of the users that did 'Like'.
My approach was to add new table to the ParseDB called 'like' with columns - ' commentID, userID. When the comment will be display, I'll make a query to the 'like' table and fetch the users that 'liked' the comment.
Is it the correct approach or this will be cause IO delays in the UI?
please give answer if you have experience with ParseDB only.
IMO solution in OP will work but you might want to consider two additional options.
In order to minimize metered query costs consider 'likes-ctr' column on 'comments. Like button cliks ++ this.
To flaten the query that join users to comments which they liked consider Array type colum. On 'comments' that hols pointer to user. APIs have ' addUniq' which nicely handle updating an array with poiter to user as long as u have ref to currentUset object.
Query.include('usersLiked')
Added will do the he join work

Crime Data Warehouse [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am a IT student and now facing problem in understanding data warehousing. I need to implement a data warehouse that will be used in State police department for crime analysis. But I am not sure how to do with measure. I will use star schema. I want to set the business question from the view of Chief office , so I guess the measures should be No of crimes, No of offender and No of victims, and I am not sure.. May I know the fact table (measures).
I would start by writing down everything you know about crime. For example:Police, Detectives, Locations, CrimeType, Crime Instance etc.
Theses could be your tables.
Link the data in the tables to make it into a database. The data in the tables may be something like:
Location: Name, Address, Type, creationDate, user
Crime: Name, Severity, Punishment, creationDate, user
CrimeIntance: Crime, Location, Date, Detective, creationDate, user
etc, etc - use your imagination

Should I create two similar tables or one? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In my database I have flights wich are formed by two air tickets in both sides. So, to create flight object I should create two tickets in both sides. The tickets have field in database "flight direction" with two values: 1)"there" 2)"from". I can't figure out how to make form where i can create two tickets with different sides at one time.
You can achieve this by using a callback in your Flight model. This callback will be executed after the Flight is created (= initialized and saved to database).
class Flight
has_many :tickets
...
after_create :create_tickets
def create_tickets
tickets.create(flight_direction: 'from')
tickets.create(flight_direction: 'there')
end
end
This will automatically create two Ticket records in database that are associated with the Flight record.

Resources