Chris Oliver

Joined

290,710 Experience
86 Lessons Completed
298 Questions Solved

Activity

Hey Sascha, what's the error you're getting? Normally whitespace like that makes no difference since it's "comma separated" which means that only extra commas would cause it to mess up so I suspect there must be something else going on.

What do you mean by exact match? If you've got some code examples, we can probably help out a bit better. :)

You should just be able to pass over Date objects to handle that accordingly. Integers should also be handled the same way. Normally dates and times get converted to seconds since the epoch, so you may observe that change getting automatically converted in the logs when it queries. I don't think there should be anything special.

You should be able to say this in your HTML to add the url there.
https://gist.github.com/exc...

Posted in Single Devise User Model or Multiple Devise Models?

An example on the forum here would be "Site Admin" (like me) "Moderator" (someone who can clean up things, delete spam, etc) and "Subscriber" (your normal users). They'd each have a bit more access to do things, but they're all the same users at the end of the day with basically no differences on the database level.

Always good to talk those out with someone because if it seems overly complicated, it probably is! :)

You won't necessarily need roles for this because simply the creating of associated records would give you the information if the user is a consumer, a seller, or both.

I would make a User model, a Consumer model, and a Seller model like so:

User
has_one :consumer
has_one :seller

Consumer
belongs_to :user

Seller
belongs_to :user

Then from the User you can check the associations simply enough to determine which type of user they are and give them access to whichever parts of the site you need. You might consider caching a role field on the user for quicker lookups, but that's an optimization you can add later.

The main downside of different models is that you are required to do separate login pages for each (and a lot of confusing links as to who signs in where). Roles take care of this and having just a single User model.

If you've got a bunch of unrelated fields, I would associate the other models with it. So maybe you're building something like Foursquare that has a user, but the user has a personal profile as a reviewer but they also have company profiles for the businesses they own. In that case, you'd just create separate profiles for the companies. Make sense?

Posted in GoRails Markdown and Preview

I'm using RedCarpet + Pygments for the final rendering with syntax highlighting and I'm using the marked Javascript library to render the previews when the text box content changes.

# Markdown previews to comments
class Comment
  constructor: (element) ->
    @element = $(element)
    @commentField = @element.find("[data-behavior='comment-body']")
    @previewArea = @element.find("[data-behavior='comment-preview']")
    @setEvents()

  setEvents: ->
    @commentField.on "change", @handlePreview

  handlePreview: =>
    html = marked @commentField.val()
    @previewArea.html html

jQuery ->
  $.each $("[data-behavior='comment-form']"), (i, element)->
    new Comment(element)

Posted in Displaying previous score in current record

Awesome work John! :) I've done that exact same thing in a few apps and it works nicely. That's going to be the most efficient way to do that because you will not know which records have been deleted (or whatever), so you'll always need to do the query to safely retrieve the associated record.

Posted in How to Upgrade to Turbolinks 5 Discussion

Ha, wow that's a subtle one. You'd think that it would automatically strip out spaces at the end of the filename by 2016. ;)

Posted in How to Upgrade to Turbolinks 5 Discussion

I don't believe so. It sounds like the normal error you get when trying to require a file that doesn't exist, although you have created it locally it sounds like. Possibly a typo in your filename?

Posted in How to Upgrade to Turbolinks 5 Discussion

The turbolinks/compatibility.coffee file doesn't ship with the gem unfortunately (at least not right now). You'll have to copy it into your Rails app from the original repo. I've got a link to it in the resources section above, but here's the link as well: https://github.com/turbolin... Paste that into your Rails app and just require the file like normal and you should be set.

Posted in Sharing on social network

That's pretty much exactly what I was thinking! Glad that worked out pretty well.

Posted in Rspec Test on Multi tanent app with aparment gem

The error says you've already created the companydemo tenant. I think the thing you're going to run into here is making sure you architect your tests properly to create and operate on a tenant and safely revert them as necessary. You'll need to add cleanup methods in your tests to make sure that once you're done using the tenant that it gets dropped. That's basically the only changes you'll need to do aside from setting up your other tests to already have a tenant setup, migrated, and selected.

Posted in Migrate away from Mandrill?

Kind of unfortunate as a lot of apps I run are in the same predicament.

One of my good friends works at MailJet and was telling me about all the things they're doing and they offer a free 6000 emails a month. https://www.mailjet.com/pricing_v3 They're like both Mailchimp and Mandrill combined, not just transactional email which is super nice in case you want to do marketing stuff as well. I think I'm going to be trying them out personally. They've been mostly focused on Europe in the past so most people haven't heard of them as much.

Of course there are all the other options: Sendgrid, Postmark, etc. I don't think you can really go wrong with any of them. I like Postmark a lot and Sendgrid is a powerhouse for transactional email that everyone knows.

Posted in In-App Messages Between Users Discussion

I don't entirely know how the attachments feature in Mailboxer works so I can only give you a rough idea of the direction to go. I think you could probably override the Mailboxer::Conversation model in your app and then add Refile into it if you didn't want to use Carrierwave. That should let you do what you want there.

Posted in Automated email notification summary

If you want to send these on a regular basis, cron jobs are perfect for that. You can just set it up to run weekly and notify users from a rake task. Easy to test and maintain. I did an episode on that a while back: https://gorails.com/episodes/cron-jobs-with-whenever-gem?autoplay=1

Otherwise if you want it to happen on a trigger in-app like a notification every time a new profile is created, you can just put the logic in your controller to check who should receive the notification and then send that out. This sort of thing is a good case for using a service object (just a regular ruby class that contains the logic for it).

Pros are you get a lot of helpers for making basic forms quicker, downside is that I often customize my forms a lot so you can't really use their helpers all the time and it's also another API to continuously memorize. I use them in things like Admin areas or forms that don't need much UI work, but other than that, I tend to just use the normal form helpers and tags.

Check out this episode! https://gorails.com/episodes/forum-nested-attributes-and-fields-for It covers how to do that with the form and params in order to properly set everything up.