Chris Oliver

Joined

234,960 Experience
17 Lessons Completed
256 Questions Solved

Activity

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! 👍

Posted in Using Pundit with ActiveAdmin

What a subtle bug, glad you caught that Dan. :) Should be fixed now.

I wonder if we can get a patch into ActiveAdmin that will correct that...

Posted in Use datatables like handsontable

This looks really cool! I'll definitely make an episode on this stuff in the near future.

In the meantime my recommendation would be to take a look at jbuilder. You can access the same routes as your forms do, but just do that in JS. Then you can and jbuilder responses like "show.json.jbuilder" right next to your show.html.erb file. That'll let you return a JSON object that your Javascript can use.

Same goes for submitting data to the server, you use the same URL as the create and update urls. Make sure the method is either a POST or UPDATE request if you're adding or updating data. The javascript library might expect certain formats for all the JSON you return, so that can help you design how to format your JSON responses for all these actions.

I don't know if that's enough detail to get you pointed in the right direction or not, but I hope that helps a little bit!

Posted in Using Pundit with ActiveAdmin

It's really unfortunate that's still happening. I don't know if this is relevant or not, but did you guys this? https://github.com/activeadmin/activeadmin/issues/3068

Because you're using Ruby to inherit from User on both the TeamLeader and Agent, you're going to get access to everything already defined in User. It's kinda like how ever controller inherits ApplicationController. You get access to all the methods there.

If you don't want the admin? method to exist inside Agent, you'll want to move it out of User and put it in the TeamLeader class instead. Make sense?

Posted in Comments With Polymorphic Associations Discussion

You'll get there! I think you can add me as a collaborator to the private project temporarily if you wanted, but no worries if not.

I would also recommend playing a lot with plain Ruby because that will help wrap your head around all these things in Rails. It's mostly just regular old Ruby code just connected in various ways. The Ruby Pickaxe book and Metaprogramming Ruby are both really good.

Feel free to shoot me some emails as well! My email's on the about page I believe.

Posted in Comments With Polymorphic Associations Discussion

No, you'll still want that to reference the variable and not the class.

Do you have a github repo I can show you some fixes for this? It's kinda hard to give guidance in the comments. :)

Posted in Comments With Polymorphic Associations Discussion

Well, that's a button_to, which is a POST, but update is actually an UPDATE request. You'd need to add the :method => :update to the button_to here.

Your destroy action should be put inside the regular CommentsController and should be in the same place as these. The only reason you need the nested routes and controllers is for helpers that make creating the comments (and referencing the original object you're commenting) on a little simpler. To destroy any comment, it doesn't matter what the original object was, you can just delete the comment itself if that makes sense.

Posted in Comments With Polymorphic Associations Discussion

I think you're passing in that variable into a partial actually(?), so that wouldn't actually solve your problem. You may need to make sure you're passing the right comment variable into your pundit stuff in each case.

Posted in Comments With Polymorphic Associations Discussion

You must link to the route that matches the destroy action. You're linking to a nested route, but you want to link to comments route directly.

Replace the polymorphic_path([commentable, comment]) in your button_to's to simply be comments_path(comment)

Posted in Comments With Polymorphic Associations Discussion

It sounds like you're passing in a variable that's nil then. Are you sure you're before_action :set_comment is being called?

Posted in Comments With Polymorphic Associations Discussion

Ah ha! So your errors is in the view, not your controller. :)

Change line 25 to say <% if policy(@comment).update? %>. Like I first guessed, you were referencing the class Comment, and not the individual record "@comment". That should do it!

Posted in Comments With Polymorphic Associations Discussion

That's exactly what I need. I might suggest removing the authorize @article in this function and keeping the one in your update action instead. Everything else looks right, so you might need to also send me the full error logs to see where exactly it broke.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.