Chris Oliver

Joined

290,710 Experience
86 Lessons Completed
298 Questions Solved

Activity

Posted in Sharing Data With Javascript Discussion

Wow, that's awesome, I'm really glad it was helpful! :)

You definitely don't need a frontend framework for this, so no worries there. :)

You're looking at some functionality that's sort of like infinite scroll on an index page, but slightly different because you're scrolling through the next and previous items individual. It's kinda like you're viewing the show action and then scrolling into the next show action.

The best solution here is probably something custom. Similar to how Ryan Bates in his revised Railscasts episode builds infinite scroll from scratch, but you'll need to add a "next" and "previous" method to the model in order to grab the next record for the show action instead of the next page of results that would be on the index.

Really I think with some minor tweaks, you could take the code from his episode to pull this off. You'd basically update the JS response to do the pushstate and append to the page, and set a link to the next episode that you can use for looking up the next result (instead of using will_paginate there).

I'd definitely like to do a screencast on this, because it's something you see popping up quite often.

Posted in CSV Import

You'll actually want to just make sure it matches the column name I think. You can print out the row hash to the console to see exactly what you'll need for that.

Yes that works! You should use your version, not the merge for this.

You can actually just add that into your query. For example, if your published column was a boolean: Post.search('*',where:{published:true})

Ah, the good ol' pebkac. ;)

It's interesting that even with the firewall, they seem to still be getting through. Maybe it's not working? I'm not well brushed up on firewall rules as I should be, but does UFW basically do the same thing as setting iptables rules?

Also you may want to make sure your log files are being rotated with logrotate so they never become unwieldy in size. Doesn't really solve your problem of constant attack, but does prevent your files from getting huge.

Posted in Get started with Rolify for roles

That's a great idea. This is definitely something that I've been wanting to cover for a while, so I'll make it happen!

Posted in Style a drop down menu with css

Hey JM,

I also added some code to remove that bell after you mark the messages as read. Once that AJAX call completes, the JS success callback just removes that div from the navigation. And that number is just the typical bootstrap CSS for the badge. You can inspect the HTML on the page to see what that looks like!

Posted in Sharing Data With Javascript Discussion

Check out the documentation here: https://github.com/rails/jb...

And my previous episode on fragment caching: https://gorails.com/episode...

Posted in Admin Interfaces with Administrate Discussion

Since these are just regular scaffolds, you can add routes and actions like you normally would. It's not really documented anywhere yet, but that's about all you would do.

Posted in Sharing Data With Javascript Discussion

No particular reason. I have been using CoffeeScript before ECMA 6 and am familiar with it so it's easy to use. Once nice thing is it's easily translatable to JS as well for anyone not familiar with it.

And yes, ECMA 6 (and 7) solve pretty much everything there. I'll have to do an episode showing how to use ECMA 6 with Rails as well.

Posted in Sharing Data With Javascript Discussion

Will do!

Posted in Sharing Data With Javascript Discussion

Polling works just fine in a lot of cases unless there's an absolute _need_ to have realtime. It's rare for notifications to need to be truly instant. The other beauty of polling is that you can just write regular old Rails and JS code which you're already familiar with scaling. Probably 99% of the time, polling will do the trick just fine.

However, that's something we'll be talking about in the future. WebSockets are a whole lot more complicated to setup, manage, and maintain, so it will be a topic for a separate series (one that's coming soon!).

Posted in Sharing Data With Javascript Discussion

That's actually what I first did, but discovered that the way I showed in the video output and parsed the JSON just fine. I didn't run into any issues with it, but if it does become a problem for anyone, escape_javascript and some additional JSON parsing in the JS should do the trick.

Posted in Sharing Data With Javascript Discussion

It will add extra requests, but they are pretty simple, plus you can enable caching around the JSON response to make it fast.

Posted in CSV Import

  1. You'll probably need to modify that hash of attributes from the row. For example, you could transform it this way:
# Accept all fields you could ever want
attrs = row.to_hash.slice(:token, :order_id, :customer_id, :utm_campaign, :ordernumber, :customer)

# Set aliases
attrs.merge(
  token: attrs.delete(:utm_campaign),
  order_id: attrs.delete(:ordernumber),
  customer_id: attrs.delete(:customer)
)
order.assign_attributes(attrs)
  1. The col_sep option is what's used to define the column separators. You can add col_sep: ";" into your CSV parser section and that should do it. Some more info here on options: http://ruby-doc.org/stdlib-2.0.0/libdoc/csv/rdoc/CSV.html

Posted in Style a drop down menu with css

I was using Bootstrap to get the notification links in the header. No extra CSS needed for basic links like that.

Posted in Metaprogramming Virtual Attributes Discussion

Sweet! I figured there might be something to do that. I only ever clear the terminal in screencasts so I always forget to look that up. :)

Posted in Liking Posts Discussion

Glad you got it fixed! 👍