RailsCasts Pro episodes are now free!

Learn more or hide this

ahnbizcad's Profile

GitHub User: ahnbizcad

Comments by

Avatar

In rails 4, you now need to change the where() method parameters explicitly as hashes. This won't work

def self.from_omniauth(auth)
  where(auth.slice(:provider, :uid)).first_or_create do |user|
  # ...

You need to change it to

def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  # ...
Avatar

Coderay documentation sucks so much. Where can I find which $number maps to which langauge? What about other options for the div? How do programmers even find this stuff out? Digging through the mess of the source code?

What the heck is textile, and why is it impossible to find any source that actually explains it, instead of just off-handedly mention it as if everyone knows what it is, and when you use it? Why do we need redcloth and we do we need textile? Assumpetions.

Do they even want people to use it? Why would you not make the documentation better. Why make it so complicated, and obscure to find out how to use it?

Avatar

If you use a session, then doesn't that mean the default devise signup can no longer be used until that session is deleted? I don't see where the deletion is handled. Since using a provider uses the new user registration path, that means the new user registration path can no longer be used to default devise login. Even refreshing with cache clearing doesn't clear a session.

Avatar

Use figaro gem. https://github.com/laserlemon/figaro
This solution is much easier, and cleaner, and easier to maintain than secrete.yml in my opinion.

set keys in application.yml which figaro specifies you create, and set keys in that file like so

FACEBOOK_SECRET: '13103103779'

Then it will be available to access throughout your application with the syntax like so

provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET']

If you're using Devise, put the above line in the devise.rb initializer file, and not the omniauth.rb initializer file. When using Devise and omniauth together, you don't need an omniauth.rb file. The syntax for the devise way is this

config.omniauth :facebook, ENV["FACEBOOK_APP_ID"], ENV["FACEBOOK_SECRET"]

Avatar

Kaminari seems to not have the prev_span_tag and the prev_span files.

It uses certain methods to reference the partials but the ones for disabled ones are missing. So how do we create a method to reference a custom disabled partial we make from scratch?

Avatar

The figaro solution is cleanest, a single source of authority, hides everything from being exposed on remote repositories, and IMO is easier than secrets.yml in rails 4. Figaro is the way to go.

Avatar

You have to make sure in your model, you don't specify "counter_cache: true" when you're running your migrations. Otherwise, it throws "marked as read only" errors. It also does this when rolling back. So take note. I haven't been able to find a way around this. It seems you have to remove "counter_cache: true" when rolling back or migrating through a migration with counter_cache.

Wasted too much time just for a simple migration -_-

Also for rails 4, the syntax should be

Project.reset_column_information
Project.find_each.each do |p|
Project.update_attribute :tasks_count, p.tasks.length
end

update_counters, reset_counters, are all deprecated.
Note that the arguments syntax is different.

find_each is preferable because it executes in batches, not all at once.

Avatar

So all that "complex" logic goes in the js files, and routing is done through angular. Does all of this make the rails functionality for these tasks redundant? How do you resolve or use both simultaneously?

Avatar

so years later in rails 4, is Kaminari still better, cleaner, and frequently updated as will_paginate?

Avatar

What is wrong with my coffeescript?

The JSON.parse line is causing the site to fail.
I cannot use var either.

jQuery ->
$percentage_neti = JSON.parse($('#vote-data'))
$('.bar-neti').css("width", $percentage_neti + '%')

(the last two lines are indented)

Avatar

Thank you so much. Simple, elegant, better.

How could you use the retrieved data as CSS attributes or element names?

1)
Once I have the rails data in js, how would I use that value to set the width of a vote bar div to that calculated percentage value?

Something like

$('.vote-bar').css("width", "#{percentage}%");
But I know the syntax is not right.

2)
How could I also use the rails text data as the name of a class? If my rails data returns 52 via json, I want to select an element named $('#item-52') in js...

Avatar

such impress. very thanks.

I think this is one of the very few resources out there that explains how rails is constructed. And it does so in the Ryan Bates's concise-yet-thorough style.

Having this primer will save so much time reading through the rails source code.

Avatar

How would you implement chosen or select2 if your has_many through join table is not using the default id as a primary key? Is the syntax author_ids something rails handles automagically in the standard join table?

Avatar

Thank you so much! The issue was pg using different query syntax. good to know!

I'm still having an issue where the existing tags don't show up when I go to the edit page.

Avatar

Would you also need a comma after 'facebook'? If not, why?

Avatar

Thank you so much, I've been looking for doing this with has_many :through for so long. I'm trying to work this with autocomplete as well. It's surprising how so few results there are for "has many through autocomplete" in a search.