Rails: CouchSurfing-Like Database Structure [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 8 years ago.
Improve this question
So my idea is to have an user A requesting any number of arrangements (any service) from another user B. Both user A and B can leave feedbacks to each user B and A (only one per user and service). Just like CouchSurfing
I had some thoughts about the setup on the database and ruby on rails, but would be glad if you would have a quick look on it, since I'm still a beginner seeking for knowledge.
Lets have a sample scenario:
But first a quick note: It's important that every user has the ability to become an acceptor or requestor.
User A requests this service off another user B (in this case user A becomes the Requestor and user B becomes the Acceptor, who needs to accept the request of user A). Once user B accepted the request, an Arragement is built having its primary key made of the ids of user A and B. Inside this Arrangement Table are several informations related to the arrangement. Once the arrangement took place, both user A and B are allowed to give feedback to the other user (but only one!)
This is why I have set up seperate tables for the Acceptor, Requestor and Arrangement. I want to control how many feedbacks a user can give database-wise.
Now each user has (for sure) a user-show-page where all of his received feedbacks are shown. Means: Every user has N feedbacks (or messages, if you see it database-wise). And that is why I extracted a Message-Table out of the Feedback-Table
In short: It should be very similar to CouchSurfing. E.G. the stay at ones home is an arrangement and both the host and guest can leave one feedback to oneanother.
What are your thoughts on this setup? Is it good/bad? How can I make it better?

Sounds reasonable, but your design limits A and B to having only one Arrangement with A as Requestor and B as Acceptor.
Generate an int id for the Arrangement to use as PK (and as the FK in Feedbacks) and you're there.

Related

combining rollback in two action rails 4 [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
It is posible start a transaction in one action and excute a rollback in another? This is why I wanna do this:
I am making an application where the user can generate an order and that order can have multiple services so I have 2 models related Order and Service. There is a form with some radio buttons and textarea where the user is going to introduce the characteristics of the service and it have 2 submit buttons, one for add more services to that order and the second next. when the user click on next is going to be redirect to a page where he can see all the services and a button for save, if the user click on save then I wanna save the order and all services(5 services generate are 5 records on the table Service and one record on the table Order). But if the user start add services and in some point decide leave the page I don't wanna save anything.
I think this can be done with some sort of rollback or maybe there is another way.
short answer: no not really.
Longer answer: transactions are, by their very definition atomic. They do what is to be done within them, then either commit or rollback.
you can't spread them over two server actions the way you are proposing, because by the end of the first action, the transaction must either commit or rollback... by the time the server gets the second action - either one or the other has already happened.
The way this is usually solved is to add a State to your order. eg a boolean column called "is committed" or something similar. The order can be created in a "not committed" state - and all your other actions only fetch and work with "committed" orders. If the user leaves the page, you can have a sweeper process clean up any uncommitted orders (ie delete them if a non-committed order is over 2 hours old).

What is the best approach to building an email alert service in rails? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am looking to build a feature where folks can be notified via email when certain content is published on our website. Users would provide their email address, select a few subject areas they are interested in and the frequency in which they want to be updated (daily or weekly).
What is the best practice for building such a system?
I figured I would start with some sort of Subscriptions table (postgres) that would have the following fields:
email
subject_areas (list of IDs?)
frequency (daily/weekly)
last_emailed (timestamp)
I could build a job that would run every night against this table which would hit each row and aggregate all content that matches the subject_areas they were interested in, generate the email and throw it into a 3rd party email service like Mandrill or Amazon.
Does this seem like a good approach or is there a better way to tackle this?
The tables would likely be:
Users (email, name)
Subjects
Subscriptions (user_id, subject_id, last_emailed, frequency)
The other part you want is a background job queuing system (delayed_job, sidekiq, or resque) that you'll put the jobs in. A worker process will process jobs and send them in another process.
Cron and BG jobs go hand in hand
Cron (or a scheduler).
Find all users that have subscribed.
For each user - figure if there is new content to send them
Load up jobs for users that have new content to receive
Background Worker
For each user_subscriber_job - build email content based and user info and subscribed content
Send email out

How to create a multi part form or wizard in Xcode [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 8 years ago.
Improve this question
I am trying to follow a few UI/UX best practices when developing a simple "request quote" form for my users.
I basically want them to fill only a few fields at a time as I guide them through it, giving them some feedback or update on cost depending on what they fill. And this is the important part, I only want to upload/save to the backend only once the user finished the whole wizard and clicks on "Complete" in the last panel. I don't want to have partial/unfinished "Quote" objects.
1) I have setup a navigation controller and added a few UIViewControllers with some fields, and I can basically step through them. Adding validation to the fields before jumping to the next field is no problem.
2) I use parse.com as my backend, and I have a "Quote" object, for simplicity's sake, let's say it has the following properties: firstName, lastName, location, date, options, price.
I ask for location and date first > then first and last name > then
options > I then calculate a price and show it to him/her > Then the user
can submit the whole thing to the server.
I looked around, and only found some indication to use a temporary xml file, which I then upload. Other results mainly pertain about http multi part requests, which I don't think relate.
Would core data be the ideal usage here? Any pointers in the right direction would be really appreciated.
Core Data is best used for local persistence of data, what you are doing is just capturing data to post to an REST url. Create an class that holds your data and pass it from view controller a to view controller b, etc. At the end, make the call to parse.com and submit your data. You can either add the logic to communicate to parse in your final view controller or put it a separate class.
If you want the user to be able to come back to the quote, then Core Data would be good to use.

User stories - Card, conversation and confirmation [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 5 years ago.
Improve this question
I don't understand a thing about the Card, Conversation, Confirmation formula for user stories.
I don't understand if the conversation and confirmation part must be written down or they remain as a dialogue, in particular the CONVERSATION part.
To be clear: is it right if a write down ALL these things in user stories? (see example below)
Or do I have to write down only the CARD part?
Example:
CARD
As a user of a coffee machine, I want to be able to purchase a beverage.
CONVERSATION
- The user will not be able to purchase a beverage if they do not deposit enough money into the CoffeeMaker
- A user's money will be returned if there is not enough inventory to make the beverage
CONFIRMATION
1 user introduces the amount of money needed to purchase the beverage
2 user selects the beverage
3 user gets the beverage
The 3 C's is a saying used to serve as a reminder on what is important when using User Stories.
A simple card to write down the requirements - as opposed to a heavy weight document.
Having a conversation - collaborating to define the requirements and understand the value.
Confirmation - agreeing on the acceptance criteria, so you know when you are done.
There is another saying which sums up the idea behind User Stories nicely. "The card is a place holder for a conversation". This highlights that the conversation is the important part, not the card artifact. The card can be discarded once the feature has been developed and automation tests written using any suitable acceptable criteria.
The format of a User Story will typically follow:
As a (role) - This can be an end user or a business proxy
I want - A description of what need to be done
So that - the definition of the value
An attempt at your scenario
As a vending machine customer
I want my change returned
So that I do not loose my money
The confirmation part could just be bullet points on the back
Change should be returned if the customer does not put in enough money and then selects a beverage
Or you can use the context specification style, a BDD (Business Driven Development) technique
Given a customer does not put in enough money
When they select a beverage
Then their change should be returned
If you would like to know more I would suggest researching the INVEST principles and reading Mike Cohn's User Stories Applied.
You can do whatever you want ;), from writing down everything to memorizing everything and writing nothing. Personally I write everything down, so the next dev that picks up the story can understand as much as I do and pick up from there.

Ruby on Rails Resource Design, singular vs. plural [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm still learning Rails and how to best design my resource structure. Could someone help me with this? Here's my problem:
I am designing a specialized social network with profiles - every account has one profile. At the moment, an Account stores basic info about the user (username, password, etc.) from when they first sign up. A Profile stores other thinks like a picture link, answers to personality questions (linked back to a Profile via foreign key), and maybe more in the future. There is a one-to-one relationship between Account and Profile. Users can view/edit their own profile and view profiles belonging to others.
My questions:
Is it a good idea to split these two into separate resources altogether (i.e. have two different models) or collapse them into one model with two controllers? I have tried the latter, and it almost seems like more trouble than it's worth. Am I, in this case, fighting against the framework? I'm not sure yet whether users should be able to have more than one account in the future.
If I do split them, should I use a singular or plural resource for the profile? I noticed in the language at guide.rubyonrails.org that get (show) and put (update) work with the ONE and ONLY profile resource. My question with respect to my current situation is: "one and only" with respect to what? The "one and only" profile for the current user's account or with respect to the entire site? If so, how could I have the current user view profiles of other users - should I use a URL parameter like so:
http://www.example.com/profile?id=x, where x is the other user's account id
If I go the plural route, does index showing "all profiles" intend to mean all for the current user or for everyone across the site? Or is this up to my own interpretation?
I would appreciate any help I can get with this, as I feel like I am starting to understand REST and RoR conceptually but am just trying to put it into practice. Thanks!
I would personally keep Account and profile as two separate resources or at the lest 2 separate controllers accessing different parts of the same model.
This allows easy routes like http://www.example.com/profiles/2 for viewing other users and http://www.example.com/accounts/2 for managing your own account without having to add custom routes.
If you have the possibility of adding more profiles to an account, then this is a form of future proofing too.

Resources