Activity
Posted in New Users Only Created by Admin User
I'd suggest removing the :registerable
option from the Devise User. That will remove all the registration functionality and you can replace it by adding in the devise_invitable
gem. This is just a plugin to allow you to create accounts with only an email and send an email invitation for the user to accept and set their password. You can add additional fields in (like Name) to be populated either when you send or when they set their password.
That should do the trick for you and then you'll have nothing but a "Sign In" section on the site. That should do the trick if you want to expose this publicly.
The other idea is to make everyone connect through a VPN, but that's always a hassle.
That's a great idea. As far as the streaming video goes, the file size won't be exact because sometimes it switches between standard and hi-definition videos. I think showing the file size of the HD version or the download file (which is the original video I uploaded) would probably help.
ES6 looks fantastic and I just need to try it out soon. Are you using sprockets-es6?
Awesome, that is great to hear! :) I really like the way this structure works for thinking about frontend code. jQuery is usually written poorly and you end up with a lot of "spaghetti code". Glad this makes sense to you.
Great question. You could use anything you want, but it's good practice to use something like "data-behavior" because the naming gives a clear purpose for what it does.
Posted in Where to put my Big Ole' Array
You could make a separate class for this. This makes for a good use case because you're really talking about a service of sorts and it's not really the responsibility of either the controller or the model. Maybe call it something like LookupService
:
class LookupService
def call(query)
if in_array?(query)
# Return value from array
else
# Look up through geocoding service
end
end
end
Posted in HTTParty and trycelery.com API
Hey Edwards,
For Objective 1, I think you'll want to do something like this:
@ids_and_names = @http_party_json["data"].map{ |item| [item["id"], item["name"] }
When you parse as JSON, you get a regular old Ruby hash and you can select out the items you want (the ones in "data") and then transform them with map
into an array of ids and names. You might need to change the order so it's Name first and then ID in the arrays, can't quite remember.
For Objective 2, I think that should do it for you and changing the product_id
would give you the right results. You'll want to probably change @percent_complete = 100.0 * @order_count / 50
to be calculation with the goal amount as a variable instead of the number 50 unless it is always 50 you are shooting for.
Posted in Must Read / Must Watch
Don’t ask people what they want. Watch them and figure out their needs. If you ask, people usually focus on what they have and ask for it to be better: cheaper, faster, smaller. A good observer might discover that the task is unnecessary, that it is possible to restructure things or provide a new technology that eliminates the painstaking parts of their procedures. If you just follow what people ask for, you could end up making their lives even more complicated.
I can't think of any other benefits. "Simpler" to manage from a database perspective, but complexity shifts to working with STI.
In this case, I usually do whatever feels easiest and just keep in mind that I need to be careful to consider this in the future anytime I start changing these around. Whatever you decide later on, you should be able to easily combine or separate these into different tables.
Posted in File Uploads with Refile Discussion
Sending files via a POST won't be any different than a normal upload form on the webpage. The browser submits forms with a POST so if your Android app or mobile browser does the same thing, nothing would change. You just need to make sure the file is sent over with the same field name as it has in the browser so it can attach to the right model and attribute.
Thanks! :)
Posted in How to build a web scraper using Ruby...
Love that idea. I've used Mechanize in the past for something like this. It's pretty fun to do and would make for a great episode.
You would just need to add a join table for the has_many. You can keep the account.user_id for the Owner of the account. This is probably the person you want to let invite new users, cancel the account, charge their credit card, etc. Use them as the special owner and you can keep the rest of the users in the has_many. You might want to duplicate this user in the has_many :users so that your functionality can stay the same across all the users without making too many exceptions for the owner.
The nested form for the user also creates the account using accepts_nested_attributes_for
. The user_id automatically gets set because it is created through the association.
Posted in File Uploads with Refile Discussion
Lots of different options here. Are you talking about importing files from somewhere else like through a Ruby script or something? Where are the images in the external application? Does it have an API?
You can just remove that line from the bashrc file. I believe it should be
export PATH="$HOME/.rbenv/bin:$PATH"
Posted in jQuery UJS Callbacks Discussion
Love these suggestions! I was originally hesitant on covering too much frontend Javascript stuff but I think you're right in that all these things are super related and all Rails apps are getting more and more JS heavy. These are becoming more important and it would be a bad idea for me to consider these "out of scope". Going to add all these to my list of episode ideas and sprinkle them in. Thanks for the list! :)
Posted in Add Profile page for users
Hey Rahul,
So basically what you're gonna need is 2 things:
- Make sure this route is AFTER
/forum
in your config/routes.rb so that your forum matches first. - You can add a blacklist into validations so that
forum
couldn't be taken as a name. This isn't required although it's good practice. If you don't do it, a user could register asforum
but they wouldn't be able to access their account. Usually this is someone trying to game the system so they'll have to reach out to you for support to change it. If you do make a blacklist, you'll have to keep this updated as you add more things areas into your site.
And as a fun fact, this is the reason why resources :users
generates /users/:id
so that you can avoid those namespacing issues. Obviously that's not always ideal if you want something like twitter or github's urls, but definitely cool to know.
Unfortunately I don't know much about Parallels. Not sure there's a way to convert the Ubuntu virtual machine from VirtualBox to it or not. It might be easiest to just install Ubuntu from scratch in Parallels.
Posted in Flexible Nested Attributes
It's been a while since I read this. :)
What I was suggesting with scopes on the association (I think) was something like this:
has_many :contents, -> { order(:order_number) }
Most people don't realize you can pass a lambda into associations like this to add scopes and other additions to the query. I always seem to forget it exists, but it can be really helpful for things like this.