Yes, you can have one app so people only have to log in once to either system. You can set current_school just like you set current_user with something like the following if you save siteA.com and siteB.com as the domain for each school.
ruby
defcurrent_school@current_school ||= School.find_by_domain(request.host)
end
Then you could use @current_school for scoping as mentioned in the episode.
Update: To make this work in XLS format, we need to pass in the tab character, so I modified my controller to look like this:
ruby
@products = Product.find_all_by_color("green")
respond_to do |format|
format.csv { send_data Product.to_csv({},@products) }
format.xls { send_data Product.to_csv({col_sep:"\t"}, @products) }
end
And then this is how product.rb receives the call of .to_csv with the tab character and @products passed in as variables from the controller:
def self.to_csv(options,products)
CSV.generate(options) do |csv|
csv << column_names
products.each do |product|
csv << product.attributes.values_at(*column_names)
end
end
end
Params seem very helpful. From the controller, is it possible to filter public activity by params (for example, storing the recipe in the params and only showing public activity for a recipe on that recipe's page)?
I see in the episode that Ryan filtered directly by one of the attributes (owner_id):
ruby
defindex@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.friend_ids, owner_type:"User")
end
I see that I can store the recipe_id from within the recipe controller similar to what was mentioned in the episode:
I see that it's possible to filter this way in the view (replacing "123" below with the particular recipe's id, but I'm assuming it's better to do this in the controller, yes?
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
defself.to_csv(all_products)
CSV.generate do |csv|
csv << column_names
all_products.each do |product|
csv << user.attributes.values_at(*column_names)
endendend
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
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.
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.
Nested attributes will need updating too:
http://stackoverflow.com/questions/18436741/rails-4-strong-parameters-nested-objects
Yes, you can have one app so people only have to log in once to either system. You can set current_school just like you set current_user with something like the following if you save siteA.com and siteB.com as the domain for each school.
Then you could use @current_school for scoping as mentioned in the episode.
Update: To make this work in XLS format, we need to pass in the tab character, so I modified my controller to look like this:
And then this is how product.rb receives the call of .to_csv with the tab character and @products passed in as variables from the controller:
Great gem.
Params seem very helpful. From the controller, is it possible to filter public activity by params (for example, storing the recipe in the params and only showing public activity for a recipe on that recipe's page)?
I see in the episode that Ryan filtered directly by one of the attributes (owner_id):
I see that I can store the recipe_id from within the recipe controller similar to what was mentioned in the episode:
I see that it's possible to filter this way in the view (replacing "123" below with the particular recipe's id, but I'm assuming it's better to do this in the controller, yes?
I got the same "can't convert Array into Hash" error from
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.
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:
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/
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
AFTER 2 CHANGES (no more errors)
I hope that is helpful to some folks.
Thanks for these truly awesome tutorials.