Activity
I was going to say, I don't think you can do that because ActionCable doesn't go through Rails controllers. You'd want to set self.current_user equal to the logic that finds the user from the session.
What was your solution? I'm sure other people would love to know it as well!
Posted in rails5 + heroku + cloudfront + fonts
Awesome post, thanks for sharing Michael! :D I need to do an episode on Cloudfront sometime.
Posted in Search all models gem
Like Andrew said, Searchkick is perfect for this. Each model gets an index inside ElasticSearch and then searchkick lets you query over those by simply doing this: https://github.com/ankane/searchkick#multiple-indices All that should make sense after watching the screencast. 😎
Ransack isn't quite the same in that it doesn't index them in a way that you could search multiple models together. You'd actually have to search each table separately and then combine the results in your view. It's nothing fancy as it just does database queries which makes it really easy to implement without any separate services, but more rudimentary in a sense.
Posted in Freelance advice
This is a great question Karim. :D Here's some thoughts from when I was consulting:
- The most important thing for me was to just get work at first. Any work at all would lead me to more people and build up my portfolio. Over time I'd "trade up" and get better and better jobs ignoring a lot of ones I probably would have picked up before that were bigger time sinks than I wanted.
- I actually just emailed a random guy on a job board and got my first consulting project that way. The majority of my work afterwards was actually from spending a lot of time in the startup community in town. All kinds of people want to start a business and need a developer to help them build it. There is always a lot of work available if you're around those people.
- I'd charge pretty much any rate you feel comfortable with. The ideal is to know you can deliver on their project with a fixed cost, but that's rarely possible to do well. Too much changes in most projects so to stay safe you can always charge hourly. To make things a bit easier on yourself, consider charging per day or per week and they have to book either a full day or full week and that way you're not losing out. You'll do well to find out the client's budget and then work with that (see what you think you can deliver for that, it might not be the full project or whatever if it's too small but you can help them start). Raise your rate by $5/hr each new client or something as you get more experienced.
- Lots of different projects was great for me to keep improving skill wise. And then for each new client I'd try different things. Like I went from hourly to daily to weekly and then tried some fixed fee projects so each new client I'd tweak one piece of the wway I worked to see how much it improved my life and if I liked it or not.
- I didn't really do any marketing because the best clients I got were actually from referrals so I focused on that. Rarely did I get good work that would show up randomly so I didn't put any time into marketing which was nice for me. A lot of people will do marketing for this, but you'll need to do something totally unique to stand out from all the other developers who claim they can "take your ideas and make them real" or any of the thousands of variations every consultant's website has. 😛
Happy to answer some more questions on this and I would love to hear about other people's experiences. I spent like 7 years consulting and made a really good living doing it.
Exactly, you can just replace that with however you find the current user normally. 👍
That turned out nice and simple! :) I hadn't actually customized it to be username/pw but that looks pretty much exactly like what I imagined you'd have to do. Nice and simple, thanks for sharing your solution. 👍
Hey Naveen,
In this case, it looks like you created a select
without a matching form
tag. The CSRF token actually gets generated by the form_tag
and form_for
helpers so if you just wrap your select with form_tag, you'll be fine. You can then move your URL
, method
, and remote
options to the form_tag
and have that all organized nicely and that should fix your issue.
The problem you saw was that, while you can try to put the remote: true
options on a select tag directly, it isn't going to generate the CSRF token to send along with.
Posted in Rails Counter Caches Discussion
This is exactly what the counter_cache option does inside ActiveRecord, it's just hidden away. You get the performance benefit from querying, with the slight tradeoff of inserting/destroying records taking 1ms or so more. That's totally fine because most applications are much more read heavy than write heavy.
As for the conditional counter caching, you're right, nothing in Rails to do that. You could probably turn that into a concern that could be reusable that accepts a proc you call to replace the `if user` portion so it could be reused and customizable in any fashion. Might even make for a nice little gem!
Another tweak you could do with that is actually do the COALESCE like you mentioned, but like Rails does, ignore the count and actually just add 1 or subtract 1 from the current value. This way you don't have to also query for the total count which would speed up your implementation slightly. It does assume the value is accurate, which is totally fine since like we saw in the episode that you can just set that when you add the new column. This way you're making a micro update to just increment or decrement the counter column rather than doing that plus selecting the count. Adding or subtracting 1 each time should only ever take a millisecond or less while the count might take several.
This was a great question!
Posted in Rails Counter Caches Discussion
Haha! It just might be. :) Someone was also asking about counter caches in Slack so it seems like perfect timing!
Just coffeescript because they removed curly braces. They use tabbing to denote which block it is a part of instead (like Python).
Hmm, not sure. It looks correct assuming each of those lines is tabbed over properly
$(document).on "turbolinks:load", ->
$("#new_message").on "keypress", (e) ->
console.log e.keyCode
You can add your own ID or class to any element you have in your form and change that query to match. I just use that because it's auto-generated and easy to use, so you can use the autogenerated one for your form, or specify your own and that should do the trick. 👍
Sounds like a good pull request for someone to submit to the repo if they have time! *hint hint*
Masud, I think you'll have to benchmark your app and monitor memory usage and things to find out what it's actually using and if it's going to surpass your limits. There's no real way to tell ahead of time, but you can also try deploying the change and making it easy to roll back in case you do surpass your limits.
If it does look like it's going to be way too much, you can always try using http://anycable.io/ which can handle 20,000 idle ActionCable connections within 1GB of memory.
There's only 1 websocket open and you can use as many channels as you want to separate messages out across that websocket. Check out the browser's websocket messages as they come across and you'll see how it groups them into the different channels. ActionCable just handles the filtering for you so you don't have to.
I would recommend either will_paginate or Kaminari. Both work really well and only have minor API differences between the two. They both have over 13M downloads too, so they're similarly popular and I wouldn't really say one is better than the other. If you use something like Administrate or something that already depends upon one, then I'd say to just use that for your app as well.
I'll be making a video how to add the pages into the JSON api spec so you can see how that's done.
Awesome to hear! Appreciate the updates notes and I should definitely do a screencast on this as well. :D
Thanks Chris! I'm going to try updating the tutorial this weekend using your notes. It's been a while since I've updated this. 🤘
There's a bunch of great options like this. Cool thing about Pretender is that it can work with anything, but the nice part of devise_masquerade is it handles all the controllers and routes for you.
Hah! Yeah, it's a fantastic improvement to keep things consistent. One protip I'd recommend is actually studying how Rails generates scaffolds and you can cherry pick ideas from what that generates to use in your own code.