Chris Oliver

Joined

291,590 Experience
86 Lessons Completed
296 Questions Solved

Activity

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.

Posted in Comments With Polymorphic Associations Discussion

Do you have the part that sets @article?

Posted in Comments With Polymorphic Associations Discussion

That looks correct. It sounds like the comment object is potentially the class and not the instance of the comment.

Does your controller have " authorize @comment" in it? And is your @comment variable set to an individual record?

Posted in 2 Factor Authentication

Oh cool, I'll definitely give it a look. I think that would be really awesome to support Google Authenticator, SMS, etc. I imagine this gem is designed to be fairly generic so you can support whichever you need.

Posted in Button Loading Animations with jQuery UJS Discussion

You'll just need to save those records to the database in the rake task and then load them up in the controller. That should be all you need to do!

ActiveRecord should always save UTC to the database unless you changed that. You can set the default time_zone in Rails to be PST and keep the activerecord timezone as UTC in order to have all form submitted times process in PST and then get saved as UTC. http://stackoverflow.com/qu...

The other thing is you could add some code either to your controller or model to set the timezone of the submitted attributes. Either approach should do the trick for you. Any form datetimes that you submit have to get cast to an actual Time object in Rails in anyways so you'd just be adjusting that process.

Posted in How do i collect the users emails into mandrill ?

Hey Ahmed,

Sorry for the slow reply on this one. You can add an after_create callback to your User model to add the email to the mailing list via their API. If you're using Mailchimp, you can use the Gibbon gem to do that.

I do something like this for GoRails when someone subscribes:

class User
    def add_to_mailchimp
    $gibbon.lists.subscribe(
      id: "a04070a071",
      email: {email: email},
      double_optin: false,
      merge_vars: {
        FNAME: first_name,
        LNAME: last_name,
        PLAN: (subscribed? ? "screencast-9" : ""),
      }
    ) if Rails.env.production?
  rescue Gibbon::MailChimpError => e
    Rails.logger.error "Unable to add #{email} to mailchimp: #{e}"
  end
end
# config/initializers/gibbon.rb
$gibbon = Gibbon::API.new Rails.application.secrets.mailchimp_api_key
# config/secrets.yml
production:
  mailchimp_api_key: MY_API_KEY