Activity
Posted in Multi select form & DB search
Hey Sacha,
For those, you actually want to querying using IN
so that SQL can look for matches in an array of IDs. For example:
brand_ids = [1,2,3] # These IDs may come from your form params from a multi-select
Order.where(brand_id: brands)
# SELECT "orders".* FROM "orders" WHERE "orders"."brand_id" IN (1, 2, 3)
And remember you can chain your where
calls to make it cleaner:
Order.where("created_at between (?) and (?)", self.start, self.end).where(brand: self.brand, team: self.team)
That'd do it, glad you got it fixed. 🙌
Hey Drazen,
Handful of different ways to do this. If you know which channels the user is joined to server-side, you can just loop through them and then stream_from
for each channel. That will setup several redis pubsub connections so you will receive all the messages across those channels.
Posted in Refile uploading via rails console
I'm not entirely sure on that one. I imagine you could write the same value in and then save without callbacks in your seeds in order to populate but not trigger Refile to do a reupload?
Posted in Refile uploading via rails console
Ah ha! I was going to suggest that because I couldn't imagine why everything else was working just fine. Hate when things fail silently like that.
You'll want to modify your authentication code to lookup the current tenant and then scope the User lookup query to only ones for that domain that way only users of that tenant can access that tenant.
Posted in Refile uploading via rails console
Are there errors on the page model after save? If you load it fresh out of the database, does the image attribute exist?
I think its mostly just not taken off due to habit. We've had position arguments and then optional hashes which are pretty much keyword arguments so it's not a big change, but it's definitely a nice one.
It's probably a good habit to start using them where they make sense from now on. I'll probably just keep forgetting to do it though. :)
Hey Earl,
What I would do is create an activity model, so you would keep track of the views, discussions, etc in a table, and then you can query for those within the last 24 hours and then count them up to determine which were the most active topics. You can query for the different types of activities and weigh some of those more than others (like comments might be more valuable than likes or something).
Does that make sense?
Here's a good article on how you could move that stuff into Postgres as a function: http://sorentwo.com/2013/12/30/let-postgres-do-the-work.html
I should definitely do a screencast on this stuff.
Posted in Searchkick search_data not working
Hey Andrew, did you get this one figured out?
I know the feeling all too well. :)
Oh I gotcha, that should be much simpler.
I believe you'll need to override the Devise Registrations controller and just define the layouts in those methods.
# config/routes.rb
devise :users, controllers: { registrations: "users/registrations" }
# app/controllers/users/registrations_controller.rb
class Users::RegistrationController < Devise::RegistrationsController
layout "new_registration", only: [:new, :create]
layout "edit_registration", only: [:edit, :update]
end
Something like that should do the trick.
I would actually recommend not trying to modify this because that's how Rails generally works. The thing is that your form submits a PUT request to /users
when you edit your user, so when it fails, the request returns HTML and that's why your browser ends up on /users
instead of /users/edit
. Since it doesn't do a redirect in order to preserve all the variables, it has to keep the URL on /users in order to generate the next page that includes the errors on it.
For you to modify that, you'd be going against the way the routes work in Rails and so your solution would be kind of hacky. This does tend to feel a little weird in development when you're testing things, but when the app is live, you'll never notice it because you won't be typing in URLs direct hardly ever.
Does that make sense?
Posted in Verifying iOS in-app purchase receipts
Hey Michael,
I'm really curious about this as well. Do you know how the process of these purchase receipts work? How do you receive the receipt data? Do you get it in-app and then have to send it over to your server for verification?
Hey Jeramae,
Are you using jQuery autocomplete for the frontend? I wonder if that's having trouble on Safari or something. It isn't likely to be the server-side ElasticSearch or Searchkick stuff if it's working fine in other browsers.
Posted in What is the best way to handle omniauth
That's one of the tricky situations you have to handle with Twitter. I need to do a screencast on this, but the idea is pretty simple and here's a link to check out in the meantime: http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/
Basically you setup the OAuth process as normal, but if the user goes through it and doesn't return an email address, you have the add in an additional step to gather their email address and/or password.
Posted in Devise: Add a select to my signup form
I would just open up an issue on their Github, ask if they'd be interested in the idea and if so, what are the things they'd like to see for it? code and document obviously, but does it need tests? that sorta thing. They're super helpful and that's basically what I did when submitting a suggestion for a feature on Devise previously.
Posted in Devise: Add a select to my signup form
You know, it'd be kind of cool if someone added a generator to Devise that would allow you to add this code into ApplicationController automatically so you didn't have to look it up each time. Maybe someone should make a PR on Devise for this idea... hint hint 😉
Posted in Migrate away from Mandrill?
Hey Mel! For the most part, they're going to be the same. You'll just setup your Rails server to connect to their SMTP server. Sendgrid has instructions on this here: https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
It's the same way you would connect to Mandrill, Mailjet, Sparkpost, etc over SMTP, just using different credentials and a different server address. I'll try to do a screencast on this sometime soon!
Hey Alan, check out this episode: https://gorails.com/episodes/forum-nested-attributes-and-fields-for
Basically what you can do is setup a form that assigns attributes to two models at the same time. This will let you create a user and their associated Company record in a single form. 👍