Chris Oliver

Joined

293,280 Experience
93 Lessons Completed
295 Questions Solved

Activity

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

Posted in Integrating Braintree (and PayPal) Discussion

You got it Josh! I just added Braintree to the GoRails checkout process so I can make a screencast showing those steps for you as well.

That's a bit longer of a process that I haven't dove into just yet, but it's not too bad. Basically you'll need to add an extra step at the beginning to onboard your "SubMerchants". You'll ask for some information on them, send it over to Braintree and save the response. It'll give you some extra information that you can use for every transaction to make it processed on the sub-merchant's account. This is nice because it doesn't make you have an escrow feature and can happen directly on their account. They outline a lot of this here which is pretty similar to what I covered in my videos, but you'll have to build a couple things from scratch like the onboarding form for submerchants. https://developers.braintreepayments.com/guides/marketplace/overview?_ga=1.80046359.1408912539.1449506584

If you do need to have an escrow feature, you'll probably have a bit more work to do. You'll be the one accepting all the money and then paying things out from your bank account. I'm not sure about all the details on this but I'm sure you could also do this with Braintree. It might make your accounting a bit more complex, but is also very doable.

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Yeah! I will do that. Generally with an individual server you want to set the number of workers equal to the number of CPUs on your VPS. Digital Ocean will show you how many CPUs you have on your machine in their dashboard and you can configure that workers variable and restart nginx to make that work.

I'll make a video on this in the future!

Posted in Deploy Ubuntu 14.04 Trusty Tahr Discussion

Hmm, I've had this a few times before. I think typically it is caused by an error in your application. Check your nginx and rails log files to see if you find any errors listed.

Posted in 2 Factor Authentication

Oh definitely! I had an account with a trivial password get hacked recently that made me think about how good a two factor auth tutorial would be for GoRails. Gonna get on that!

Also, do you know if this gem uses Twilio for a backend or is it generic in that it could support anything? I haven't looked at this much.

That's a really good question. As far as I know, you can't extend it or create a hold for a longer period of time.

Kickstarter simply saves the card to be charged at a future date and does not create holds on the cards. This is also bad for your customers because they can't actually use that money on their credit card in the meantime. You also don't necessarily know if the project will get fully funded, so it doesn't completely make sense to reserve that money from your users. The only downside to this is you'll see a portion of those pledges get declined when the project is fully funded. Kickstarter provides a "Fix payment" process when the pledge gets declined that you can read more about here: https://www.kickstarter.com/help/faq/backer+questions

Generally I'd say for crowd funding, you'll want to stick with Kickstarter's approach and not apply holds. You can then spend your time designing the failed pledge process so that that is really smooth when a card fails at that time.

Posted in 2 Factor Authentication

Yes! I've actually had this on my list to cover really soon. I'm going to try to squeeze it in after the Rails 5 videos I want to cover. This is becoming so common, it'd be really important to have a video on it!

Posted in Button Loading Animations with jQuery UJS Discussion

Yeah! That would be much better I think. You can write a rake task to do the sync and then use the whenever gem to schedule that to run on a nightly cron. https://gorails.com/episode...