Chris Oliver

Joined

290,590 Experience
86 Lessons Completed
296 Questions Solved

Activity

Posted in Best way to render a page as a PDF

Unfortunately PDFs are a pretty tricky thing. I've been using Prawn, but it's annoying to use.

I haven't used it, but I think wicked_pdf is probably the way to go.

Posted in Exporting Records To CSV Discussion

I believe that ActiveRecord::Relation remembers which model class it originated from, so when you call "to_csv" on a Relation it knows to delegate it to the User class. This is how scopes work too. It functions in pretty much the exact same way.

Posted in Forms With Multiple Submit Buttons Discussion

Yes, published_at is a column and published? Is just a method delegating to published_at? so it's more readable.

Posted in Displaying an address from a selected location

It's basically gonna be like this I think with a regular select tag.

<%= f.select :location_id, @locations.map{ |c| [c.title, c.id, data: {icon: c.icon, description: c.description}] %>

Posted in Displaying an address from a selected location

This is pretty simple actually. Just did it on One Month's app. You'll add data attributes to the options in the select, and then you can grab those on change to display on the side. This is using simple_form, but you can convert this to a regular select_tag.

<%= f.input :location_id, as: :select, collection: @locations.map{ |c| [c.title, c.id, data: {icon: c.icon, description: c.description}] } %>

Elsewhere you would have an empty div for the location details:

<div class="location-details"></div>
jQuery ->
  $("#location_id").on "change", (e) ->
    selected = $("#location_id option:selected")
    $(".location-details").html("""
    <img src=#{selected.data("icon")} />
    <h3>#{selected.text()}</h3>
    <p>#{selected.data("description")}</p>
    """)

Of course, if you have an item pre-selected, you can have the JS fire the function on page load as well to use the selected data.

Yep, I believe so. Python makes it always explicit, but it can be a little confusing in Ruby since it isn't required to access but it is require to set attributes.

Posted in Upload Progress with Refile Javascript Discussion

I can but it might take a while. In the meantime, you can check out their backend section. It pretty much walks you through it all. Just need to know your Key and bucket name from AWS. Just create your S3 bucket first and fill in the rest.

https://github.com/refile/r...

You can apply scopes to ransack search results to also include it in the query. @q.result.my_scope

You're right that you should get body in the controller in params. In the controller you should get params[:q][:subject_cont] with Ransack.

Yeah they are. Check out the Mandrill episode to see how I set that up. https://gorails.com/episode...

The only real time you need to use "self" in the model methods is when you want to assign an attribute. Not using self will create local variables. If you're just working with the values and not changing them, you don't have to use "self".

Posted in File Uploads with Refile Discussion

Unfortunately that wouldn't make a difference. That feature is controlled entirely by the browser on the device. It will work differently depending on the OS version and browser.

One thing you can try is to play with the accept and capture attributes on the file field itself and see if it will trigger different things on your Android browser. I can't find great documentation on it though, but check this out to get started. http://stackoverflow.com/qu...

Posted in Forum Series Part 6: Search with Ransack Discussion

You need to pass in params[:q] so it passes in both the name of the field and the search you want to do on it. Since it supports multiple fields in search, you pass them all in instead of just one.

Posted in Is Devise always a good choice?

Glad you like it!

I found another one recently called action_access that looks to have a wonderful API but I've never used it before. Hope to do a screencast on it soon.

Posted in Is Devise always a good choice?

My preference is Pundit over CanCan because I find it clearer to understand what's going on.

Posted in Is Devise always a good choice?

That's probably what I would do. I'd have a single User model, authenticate with Devise, and use Omniauth's Devise integration to manage that Facebook and Twitter login.

With Facebook you get an email, Twitter doesn't give you one. Since you basically need a User as the main account for everyone, you'll need to ask for an email (and preferrably a password) after they login with Facebook or Twitter. You can prepopulate with Facebook's email and leave it blank for Twitter. The user can then confirm this is the email they want to use on their account (and optionally a password).

Then you can create their User record, save their Twitter or Facebook account as an associated model to the User. I usually call this Service.

class User
  has_many :services
end
class Service
  belongs_to :user
end

And your Service would store things like the social network name, their username/ID on the social network, and any other metadata like their avatar url.

That way they can then sign up with Twitter or Facebook but you've also got an associated User record.

Signing up as User first and then being a contestant means that you simply look up the User with the email they provided and associate the Twitter/Facebook account with it instead of creating the User.

Posted in Setup Ubuntu 14.04 Trusty Tahr Discussion

Thanks! I've added that to the instructions. :)

Posted in Setup Ubuntu 15.04 Vivid Vervet Discussion

Awesome! I'll be sure to tweak those soon since the final release comes out soon!

Yes it does. It's basically creating an array with one item in it and that item is the User from the belongs_to relationship. You can't do "current_user" because it's a method that's only available in the controllers and views. In the model here, we only have access to the current ForumPost record and it's associations.

Posted in Is Devise always a good choice?

That's a great question. Do you think you want separation between your account as a contest creator and as a contestant? It may be easier to manage to separate them by doing something like Admin and User, but it might also be confusing. If I create an Admin account and then click on someone else's contest, I would have a separate User account from my Admin one without realizing it. That might work fine for your application, but I just wanted to see if you had any reason to keep them connected.

If you keep them connected, you could connect the Twitter & Facebook accounts to a User, skip the Admin model, and then allow contest creators to attach their Facebook and Twitter accounts so they can see both the contests they created and the contests they are a contestant in. Depends on what you're going for here.

Do you have any preference either way?