I have a ruby on rails app that lets users create anonymous profiles with their ideal jobs. Upon approval, I want to create a method that pulls 5-10 random users (who also have approved profiles) and send them an email asking to give feedback on the just-approved profile. I can do the email sending fine, but I am not sure the best way to get the random users as I need to. I can query for the approved status easy enough, but the randomization in some sort of loop is where I am unsure the best way to proceed.
You can get 5 random users by
User.order(Arel.sql('RANDOM()')).limit(5) # Postgres
User.order(Arel.sql('RAND()')).limit(5) # MySQL
Related
So I have everything implemented with braintree and rails. However, I wanted to switch it up a little. I have a user role which is a business account. When someone wants to sign up as a business account I want them to pay before the devise registration is actually saved? I've seen it on a lot of website but cant really find any resources online how to do it. Someone please give an example of how it can work.
As a general Idea what you can do is one registration of user on business account take the card information also for billing.
On submit of that information it will go to a controller action with all the params of registration and billing.
Try to charge the card through brain tree and if they payment is successfull you can register the user because you have access to the params and you can save this transaction for the user also.
Its just a general idea that how can you implement it.
As one of the comments say, you question is vague.
What I would do is to have a column in that table that tells whether the record has payed or not.
If it hasn't payed then restrict its ability to log in. This way you can still record its information and it may be usefull for some cases, say to remind that user through an email that he/she should complete its payment.
I'm using omniauth to authenticate a user via Google. When the user logs in via Google, I check if an account already exists with the same email (if it does, I reject sign in).
When I create the new User model, I give it the name, email, and the URL of the user's 'image'. I am not sure how to dynamically update the information in my database when the user changes their settings on Google, including the image_url when they change their profile image.
A good example of this scenario is this Stack Overflow; I signed up to SO with Google. Having changed my profile image (recently), I was surprised to find that my old Google image remains attached to my SO profile. Maybe it takes time for Google to change the old URL to represent the new image. I have noticed that some parts of Google use my new image, and other parts continue to use my old. Of course, this question doesn't have much to do with Google's profile image mechanism, I just think this is a perfect example.
My questions are:
Should I want to do this, or should I instead provide the user the ability to change their details through my site, completely ignoring what happens to their Google profile?
If I should do this, what is the best way? Checking on every login isn't ideal as the user might not log out for days or even weeks.
Should I be storing the Google auth token? Currently, I'm not as I don't need to make any Google API calls -- I only use OAuth for the 'uid' to ensure it's the same account logging in (the email isn't used at all).
I don't think the answer will be "don't store user info, query Google instead", so I'm not really sure what best practice is in this scenario. A brief walkthrough on proper procedure would be very helpful.
Normally, oauth applications will use the endpoint /me.json as part of the login process: After the user is signed in, the app uses that fresh token to query their profile info right away and update data. In your case, I understand you ignore when email already exists. You should probably add a new step there, to update your local record if it already exists instead of purely ignoring it.
In other words, your app wont be automatically notified if users change their profile pictures. But you can always use their log in action to fetch the latest image (or use their token in a background job that runs every n periods of time using something like cron + whenever, assuming the oauth scope authorizes offline access)
I need to send emails to the user who sign up on my system. So, for instance say a user sign up today then after 3 days they should receive one email. Then after 6 days he should receive another email and so forth. There are 8 emails with the interval of 3 days.
I need to run a task where every midnight or every 12 hrs and that task should check whether are there any user who created account in 3,6,9,etc days before. I am aware of Rufus-Scheduler and even it works fine but I am not sure it is good to use it as my production configuration is unicorn and ngninx.I am also using sidekiq in my application for devise async emails.
Is there any other way to implement this or what would be the best way to implement such a system. Thanks in advance for help
My best recommendation would be:
sign up for an account on mailchimp
add the relevant mailchimp gem to your app
when a user signs up to your app, send an API request to mailchimp to subscribe the user
on mailchimp, set up a campaign that has the emails for the user at the required frequency...
don't forget to unsub the user from mailchimp if your user deletes their account on your app
Use mailchimp because you'll get better visibility on open/close rates and it will automatically deal with things like the user wanting to un-sub from your emails (which you are required by law to allow them to do). You also get better ability to do nice things with filtering the list of users eg sending a special email to users that have not yet seen the X email or who opened every email...
You can use reschedule method of sidekiq
Sidekiq::ScheduledSet.new.find_job().reschedule(1.day.from_now)
The idea is not to use email addresses for uniquely identifying users for a contest submission form I need to build. Since emails are not unique and google allows emails with periods in them which makes it difficult to say if email is unique or not.
My requirement is the user is able to submit 2 ballots against an entry which gives them two spots. When the user lands on the page, I ask them if they are a new user or a returning user. If they are new user I generate a unique guid on server side and give it to them. If they are returning user I ask them to enter the guid provided and then I check this on my db to make sure its there and then show them the thank you page if they have casted all 3 votes or take them back to the page where they vote on facebook or twitter.
any thoughts? I think using guids I can guarantee noone would cheat the contest unlike emails which are not truly unique.
I'm building an iOS app with a Rails backend. The user can log into the iOS app with Facebook.
What is the best way to associate this with a User record on the backend?
My thinking is to get the Facebook UID, check if a record exists with that ID in the Users table and if not create an account by storing the UID and Facebook email. Is this the correct way this should be done?
I haven't written a system like this before so I want to make sure I'm not going about it completely the wrong way.
Thanks
it looks like you might want to check out parse.com as a backend service
But either way what you suggested is pretty much how they are implementing it and they were acquired by Facebook so I believe they do it right:
add a column called 'fuid' to store the Facebook ID and check if such an entry exists before adding a new user entry to the User table
I think this railscast will be a good way to start from. For the database of app you can create an authentication table where you can store the type of authentication(in case you change your mind and want to sign up users from twitter or somewhere else), uid and the access token. You will also need a users table where you can store all the information related to a user. Not to forget a user will have many authentications or one authentication depending on your need.
As for the flow of app you can go two ways:
a. You get the users approval from the facebook, store access token, uid and get users email, first name or whatever information you need and then store it all in the back end and then sign up him/her.
b. Get the approval from user, store uid and access token and then render a form which will be filled with the user's information like first name,last name etc. User will create a password for your app and then you can sign up him/her.