Activity
Posted in Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion
Check out something like this https://gist.github.com/Glo...
Posted in Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion
You'll either need to do separate searches and combine the results or index one main model and include the nested models attributes in the index.
Posted in Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion
Hey Aime! Sorry, I've been meaning to get back to you but have been behind.
Source code: https://github.com/excid3/g...
And searching multiple models works a bit differently. For example, you would want to index and search Post, but the fields you would index should include both the comments and tags. This is what I did for indexing tags in the example.
Another way to do it would be to search those separately and combine the results. Facebook does it this way for example.
Posted in Firefox rendering issues
Hmm, you're right. I would check a couple things:
- Make sure you're including any of the browser specific tags that you might be using for newer css styles. Make sure you include any of the
-moz
ones just in case https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions - Verify your CSS isn't missing any curly braces or anything. For example it looks like
.tab-container .etabs
works just fine in Chrome but on Firefox that's not getting matched. Seems odd, so maybe the CSS for that specific tag has some error that causes it not to get parsed properly in Firefox.
Turbolinks actually does all of what you're describing with the new partial functionality. I made a video on it on another service that I was fiddling with.
You can check out the video here: https://www.livecoding.tv/video/new-turbolinks-3-features-with-ruby-on-rails/
Posted in Subscriptions with Stripe Discussion
You can swap a lot of the JS out with the Stripe Checkout button. The same process works there. You'd keep the token callback and server-side code. It's pretty much the same minus the form and the JS listener for submit. :)
This is an awesome question. I've dealt with this in the past and I'm also going to be adding a "watched" feature to GoRails. So how do you tackle it efficiently?
There's a bunch of different ways to go about this but they'll all involve caching of some sort.
- Easiest option is to simply just render the thumbnails without the "watched" functionality and then change the thumbnail class when the page loads via AJAX. Use JS to gather all the thumbnail video IDs on the page, make one request to the server to see the user's status on each of those, return the result back, and then add a "watched" class to the thumbnails that triggers the CSS to display that.
This would be super easy to build and would be pretty efficient. Basecamp has talked about using this approach in their app in a few places. Super lightweight and also allows you to cache the thumbnails globally. The results of the watched AJAX request can also be cached and you can bust the cache when the user watches a video. This would make it pretty quick and the page load/parsing time should be fast enough that it wouldn't be hugely noticeable.
This approach breaks down when your "watched" AJAX response is slow. Users would see the thumbnail and then some time later it would change to be "watched" which could be an odd user experience. Therefore... option #2.
- The second option is to cache the "watched" state of the thumbnail for each video. You can render your page like you mentioned above, but cache the thumbnails and toss the current user in the scope so you can have a cache for each user and their watched status. When they watch a new episode, only the cache for that user and that episode would change.
Basically just doing this around the thumbnails:
<%= cache [current_user, video] do %>
<% if current_user.watched?(video) %>
<% else %>
<% end %>
<% end %>
In both these cases, the best bet will be to make one single query of the user's activity to get all the user's watched videos at once instead of separate queries.
Instead of a bunch of queries hitting the databaselike this:
current_user.activities.where(status: "watched", video: @video).any?
Load them all up, and do a quick lookup instead
@watched_video_ids = Video.joins(:activities).where(activities: {status: "watched", user: current_user}).pluck(:id)
And in your views, you can just check if the video is in the instance variable instead of hitting the database
<% if @watched_videos.include?(video.id) %>
# watched
<% else %>
<% end %>
In the short term, both of those solutions will be most efficient by loading up all the watched videos at once (until they've watched thousands of videos of course) and then just checking that array rather than going to the database each time.
Your mileage may vary, and the most efficient solution in the long term will really be determined by how usage of your app ends up being. For something like GoRails, there aren't that many episodes so loading up an array of each video ID that you've watched will be pretty quick. For YouTube...that's a whole different story and they'll probably do a much different solution. But they've got the time and money to spare for that. 😉
Posted in Stripe Payments
Always the easy things! 😉
Last night I got tripped up on making a pluralization mistake for like 45 minutes. :)
Posted in Stripe Payments
It sounds like you've got everything but may just need to restart your rails server to pickup the constant in the config file. Have you tried that?
This is an interesting one. I would do one of two things to assume the order for the records:
- I would use the database ID order or created_at to determine the order and
- I would mark those as taken or "complete" as you mentioned.
With #1, you could assume that you've got the items in order as they came in. You could store each item individually as a record, or the batches that are put into stock and then count down. If you do the latter, you would want to keep a quantity and used count, so once the used count equals the quantity, that batch would be assumed used. I'll just show some example stuff that assumes there are individual records for every item.
class Item
scope :available, ->{ where(used: true) } # Let us easily grab the available items
end
has_many :items, ->{ order(created_at: :asc) } # this can have a default ordering set like this so they're always accessed in order
def take_items(quantity)
taken_items = items.available.limit(quantity) # Grab X number of items
taken_items.update_all(used: true) # Mark all of these as used
taken_items # Return the taken items, so then the caller could sum the price (taken_items.map(&:price).sum or something similar)
end
Does this direction make sense to you?
That sounds about right. Ffmpeg isn't installed by default. You can probably use this: https://elements.heroku.com...
It's /vagrant
Duplicate table as in database table from a migration?
If you want the entire thing to roll back on any failure, you can put the transaction around the foreach.
Posted in 2Checkout in Rails
I'll check it out and see if I can do that soon! It's definitely tough that Stripe and Braintree are mostly US based services so I totally understand your pain. 2Checkout seems like it's pretty good.
In production I typically use Passenger because it has really great performance. You can also use thin but you'll have to set it up differently than I've laid out here. Check out some things like this: http://www.rackspace.com/kn...
You should be able to just wrap it in a transaction block like so: http://api.rubyonrails.org/...
Anytime! Always happy to take a look or brainstorm with you.
I see your point there. I'd probably have a better answer playing with the code. ;)
Another solution for that would probably be to create those classes when AJAX completes the loading of the new answers (i.e., load new answer and then create a new Answer class for each)
That's probably what I would have suggested as well. Create a new Answer instance for the element you just inserted. If you're injecting the Answer HTML into the page in a create.js.erb file you could probably just do it there as long as your CS class is globally available.
And yeah, AnswerList should contain all of those. Hard to name things without seeing the HTML as well. :)
Also note, I haven't tested any of this code, so I doubt it works without a couple fixes here and there.