Activity
Oh nope, screenshot should be .jpg if it wasn't.
Ah, I gotcha. So in your films/comments_controller.rb
you could say:
def index
@comments = @film.comments.where(status: 'published')
end
And then you would want to build the index.html.erb to display all those comments. Is that what you're looking for?
Hey Melanie! :)
If you wanted a route to get all published comments (not ones scoped to a commentable type) you could add a resources :comments
that was not nested in your routes and use that.
resources :comments
resources :actors do
resources :comments, module: :actors
end
resources :films do
resource :comments, module: :films
end
And then you could make a comments_controller.rb that worked for all comments for any object. Is that what you're looking for?
Posted in Use .ENV instead of Secrets.yml for keys
Yeah, Heroku's stuff is easy because you can say heroku config:set AWS_SECRET_KEY=xxxxxxxxxxxxx
and it will set the ENV variable for you, and voila! You've got ENV variables set.
Much easier than doing that on your own server since nginx doesn't let you set ENV variables in your server config. When you've got your own server, it's easier to write the secrets.yml file on the server only in the shared directory between deploys and then symlink it during deploy instead rather than using ENV variables.
Yeah, you'll want to sanitize it. I can't cover everything in the series, so that's one you'll have to add in. Good catch, it'll be useful for anyone else following this to be aware of that.
More stuff coming soon! :D
The simple solution for most of Bootstrap is just to use the turbolinks:load event for re-initializing your JS. For example, to enable tooltips and popovers for all pages, you can do:
$(document).on 'turbolinks:load', ->
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="popover"]').popover()
Some of the other things like bootstrap modals don't need this because the JS is written in a way that makes it automatically compatible from what I've seen. Bootstrap 3 doesn't have too many compatibility issues with Turbolinks 5 these days.
Posted in rails5 + heroku + cloudfront + fonts
Yo Szilard! It's been a while since I've setup Cloudfront especially with fonts.
Did you make any progress on this?
It's not quite right. You do lose some of the benefits of sass if you use requires because you can't share sass variables or mixins between files with requires like I talked about in the episode.
The thing they don't talk about is the compile times are incredibly slow when you don't split up your code in requires. When your sass code is modular, you can absolutely split it up and use requires for compile performance in development.
Hey Emil,
For the most part, you can just plug in Shrine by opening up a File object in Ruby and then assigning it to the shrine attribute and calling save. That's basically the same process that Shrine uses on a browser upload so there is little to no difference to do this from an already downloaded file.
download = File.open("PATHTOFILE", "rb")
@record = Record.where(youtube_id: ID).first_or_create
@record.video = download
@record.save
You might need to delete the file you downloaded once this is complete so you don't have duplicate files on disk.
Posted in Advanced Search, Autocomplete and Suggestions with ElasticSearch and the Searchkick gem Discussion
These are likely the two main ones that could be misconfigured:
1. Make sure elasticsearch is bound to the public IP address and not just running internally.
2. Check to make sure the port is open on it through the firewall.
It's probably one of these two but could be something else. It's been a while since I setup ES across machines.
Posted in How to send Webhook?
That's relatively easy. You can just save a record for every attempt and create/update those according to the number of attempts and they display them on that page. Just need to record the results of the background job after it succeeds or fails and that should be it!
So Heroku won't actually allow you to store files permanently on their servers. You are required to use an external storage service like S3.
If you deployed to Digital Ocean, you can store files since you control the server. Migration isn't the worst, but it can take some time. If you plan on people uploading a lot of files, it's probably worth just using S3 from the beginning.
In either case, I guess I would say you might as well just use S3 from storage from the beginning if you plan to using S3 later.
Hey Nino!
I'm not quite sure what's happening. You'll have to define what "When I try to change the provider on a test account the change fails." means. What isn't working?
Also remember that all these users won't have put in a password, so you'll have to get all of the LinkedIn users to do the forgot your password process in order to setup passwords for them for the first time.
Hey Stan! Like an XML feed of them? If so, it's relatively easy. You've just got to create an index.xml.builder
view which will let you render XML.
You can access all the instance variables you need from the controller just like a normal view so you can loop through the posts and print them out in the XML. I believe you'll want the tags and structure mentioned in the following example to conform to what the feeds need for tags.
Basecamp uses this for their feed, for example:
xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
xml.channel do
xml.title(@feed_title)
xml.link(@url)
xml.description "Basecamp: Recent items"
xml.language "en-us"
xml.ttl "40"
@recent_items.each do |item|
xml.item do
xml.title(item_title(item))
xml.description(item_description(item)) if item_description(item)
xml.pubDate(item_pubDate(item))
xml.guid(@person.firm.account.url + @recent_items.url(item))
xml.link(@person.firm.account.url + @recent_items.url(item))
xml.tag!("dc:creator", item.author_name) if item_has_creator?(item)
end
end
end
end
Posted in How to send Webhook?
Btw, definitely doing a screencast on this soon.
Posted in How to send Webhook?
The cool part about webhooks is that they're just HTTP requests. All you have to do is collect a URL from your user, and then make a POST request to it with some data. I would recommend using rest-client for making the POST and sending it from a background job so that you can retry it if it fails. That's really all their is to it.
You ideally want to schedule your retries for extended periods of time, so if the first one fails, retry in a minute, retry in 5 minutes, retry in 10 minutes, 30 minutes, or something like that where there is some backoff. And then after X number of tries you can give up.
Posted in Rails csv import with associations
Posted in Rails csv import with associations
I'd toss a byebug in there and inspect each line to see what's causing it. Make sure a_categories is just an array of one item, then make sure categories is just an array of one Style, and so on.
Also keep in mind that you changed to operate on the Join table where I was showing querying the Category table instead. The reason for that was the query can verify those Category records exist.
Your code works differently than my example and needs to change a little if you do want to skip the verification that the Categories exist like mine did.
It's okay to do that, but instead of doing a where query, you would want to just do something like this:
a_categories.each do |category_id|
post.styles.where(category_id: category_id).first_or_create
end
Note that this does not verify if a category ID is correct. If you put in say, category ID of 99999 and there was no Category record with that ID, you'll be inserting invalid data into the db. This might be fine, or it may be something you don't want, so I'd be careful with that.
Posted in Rails csv import with associations
Another thing to double check with this is to make sure that it's idemopotent, meaning if you import the same csv twice, it doesn't create duplicate categories per post. I'm not sure if assigning the categories like that will or not, but it's worth checking.