Sign in through GitHub

LucasCioffi's Profile

GitHub User: LucasCioffi

Comments by

Avatar

I got the same "can't convert Array into Hash" error from

products_controller.rb
format.csv { send_data Product.to_csv(@products) }

but it seems to work if you pass @products as a variable into the model by adding it in the parentheses and in the .each loop as I'm passing all_products in below.

product.rb
def self.to_csv(all_products)
  CSV.generate do |csv|
    csv << column_names
    all_products.each do |product|
      csv << user.attributes.values_at(*column_names)
    end
  end
end

The advantage is that you can define @products in the controller in order to only get the products you want such as in this example:

products_controller.rb
@products = Product.find_all_by_color("green")
respond_to do |format|
  format.csv { send_data User.to_csv(@products) }
end      
Avatar

Great job in this railscast!

I was hoping that Facebook lets a user export their friends' email addresses to external apps so that a user can see which of his/her other friends are already using that app. Facebook doesn't allow this, for better or worse (probably to maintain control and to prevent spam).

The above functionality of helping a user find their Facebook friends on your app can still be accomplished, but it requires that both users go through the trouble of connecting their Facebook accounts to your app. This is a significant barrier, I believe.

Fortunately, I found that OmniContacts enables a user to import their email contacts directly to your app: https://github.com/Diego81/omnicontacts/

Avatar

Using Rails 3.2.3, I did have this error but it is fixed (see below for changes):

You can see I was using different variable names than the example, but hopefully the comparison between the two code snippets below will indicate what might be worth changing in your code.

ERROR
undefined method `klass' for nil:NilClass

BEFORE CHANGES

ruby
<%= user_form.fields_for :aois do |aoi_form| %>
  <%= render 'aoi_fields', f: aoi_form %>
  <%= link_to_add_aois "New AOI", aoi_form, :aoi %>
<% end %>

AFTER 2 CHANGES (no more errors)

ruby
<%= user_form.fields_for :aois do |aoi_form| %>
  <%= render 'aoi_fields', f: aoi_form %>
<% end %>
<%= link_to_add_aois "New AOI", user_form, :aois %>

I hope that is helpful to some folks.

Thanks for these truly awesome tutorials.