It turns out I have xcode 4.3.2 installed but not the command line tools (xcode-> preferences -> downloads). When I ran brew --config it showed my Clang as: 2.1 build 163. After downloading/installing the xcode command line tools brew --config shows Clang: 3.1 build 318.
Then I reinstalled postgresql (brew uninstall postgresql / brew install postgresql) and restarted my server and BAM my postgres command line tools worked...no more segmentation fault.
better still, how about making share_review an instance method? e.g., current_user.share_review(movie) (also it should take a movie object, not a movie URL..)
Wow thank you @Barwin! I've been wrestling with this for the past 2 days and just couldn't figure out what I was doing wrong. I also had a respond_to block and just needed to pop in a format.js. Works like a champ.
Perhaps it's a dumb question but imagine that you have 400.000 products
in this chain of wheres conditions (with pagination)
ruby
products = Product.order(:name)
products = products.where("name like ?", "%#{keywords}%") if keywords.present?
products = products.where(category_id: category_id) if category_id.present?
products = products.where("price >= ?", min_price) if min_price.present?
products = products.where("price <= ?", max_price) if max_price.present?
products.page(params[:page])
The search execute the first, and then filter with the other where condition so you have a 400.000 products search that kill performances, or am I totally (I wish) wrong?
Thanks Nik! The GoDaddy coupon code for the $12.99 1-year SSL certs from retailmenot.com still worked (2012-07-13). But during checkout, if you extend it from a 1-year cert to more years, the discount applies to each year! I got a 5-year cert for only $64.95! For once, I'm glad GoDaddy is so crappy.
(If you start with the 5-year cert, then it only applies the discount to the first year though).
Can anyone help me out in this. I am using dynamic fields to generate the ranges. It all working fine but now I have to put some validation over it, and have to do it on Client side. Now I have spent three valuable days to find out the answer but yet not successful. Is there any way to generate my own predecided id to each dynamic text field instead of current date and time? So that I can do the validation using that Id. Or do any one have any better idea? Any type of help will be appreciated. Thanks in advance.
I almost fell over too not knowing this. The fact that Rails is reserving a connection I guess part of the 'magic'. I'm wondering now if there's something out I can use to tell Rails not to reserve a connection, or to make controllers explicitly define whether they require a connection...
Thanks again, Ryan. You say that adding an authentications model is not always necessary to have users authenticate through multiple services. What is the alternative to an authentications model? If there is only one :provider and :uid field, how can you store provider ids and uids from multiple services in the user table?
Lets say I had an app on heroku, with omniauth configured to let users sign in with twitter. Would I need an SSL certificate on my site, or is it safe without one?
HOw would you send the message after that? I can generate the form, but I'd like to see the continuation, where he commented out in the controller.
Thought to use NotificationsMailer.new_message(@message).deliver but this gives me error: undefined methodattribute' for Message:Class`
This may be due to the fact we dont use activeRecord.
Unfortunately I've never gotten it to work. I uninstalled the pg gem (I had both 0.13.2 and 0.14.0 installed) and re-installed 0.13.2 with:
sudo gem install pg --version 0.13.2 -- --with-pg-config=/usr/local/Cellar/postgresql/9.1.3/bin/pg_config
to no avail. Still getting "segmentation fault: 11" when I get to the psql prompt with "rails db" or with something like "psql -U [username] [db_name]".
I've been playing with this setting and have run into a bit of a gotcha.
tl;dr - models don't load in rake tasks/migrations - do this: config.threadsafe! unless $rails_rake_task or explicitly require the model.
The dependency_loading = false setting in the threadsafe! method means that you won't have access to your models in migrations or rake tasks (ie. db:seed).
For me I had to use the serializer even on a simple model reguardless of it accepting nested attributes. I had a simple table with two fields type and data, where data was hstore and the model had absolutely nothing but validates_presence_of and it would not work until I implemented the serializer, without it, it kept sending it the Raw hash.
Just a note (although it's already mentioned in the episode): The code of the voted_for? method is inefficient. The problem is that it actually instantiates an ActiveRecord object which, in this case, is rather unnecessary.
Instead of this
ruby
defvoted_for?(haiku)
evaluations.where(target_type: haiku.class, target_id: haiku.id).present?
end
you should use the exists? method:
ruby
defvoted_for?(haiku)
evaluations.exists?(target_type: haiku.class, target_id: haiku.id)
end
If you are using scopes or something like that, you can also suffix it to a relation:
ruby
defvoted_for?(haiku)
evaluations.where(target_type: haiku.class, target_id: haiku.id).exists?
end
In both cases, rather than instantiating an ActiveRecord object, it would just call the connection's select_value which is way more efficient.
Side note: The exists? and its sibling any? are also helpful for use cases where you want to render a collection or, if it's empty, show the user a message like "No comments yet" or whatever.
I am having a problem though with using exactly the same template on both the client and the server. I explain better in the README. Any comments will be appreciated.
I am having a problem though with using exactly the same template on both the client and the server. I explain better in the README. Any comments will be appreciated.
This is not an issue specifically with this episode's code. You upgraded from 3.0 to 3.2. Rails already told you what you need to do. Two things:
You did not specify how you would like Rails to report deprecation notices for your development environment, please set config.active_support.deprecation to :log at config/environments/development.rb
You need to remove the debug_rjs config option from your environment files as it was deprecated in 3.1 and removed in 3.2.
This is just amazing...I found the dataTables plugin a while ago and was trying to figure out all out for a few hours. So I come to railscasts to see if Ryan had anything similar, and lo and behold...he's got an episode on the exact plugin I'm using. This has happened so many times it scary - I'm trying to figure out how to use something and Ryan has an episode on exactly what I'm doing. Railscasts is well worth every dime! Thanks for your awesome work, Ryan.
This doesn't work for rails 3.2.5.
I've removed 3.0.0beta from Gemfile and issued bundle install but when I try to run server with:
rails server
I'm getting error: https://gist.github.com/3098891
Is there a reason for not passing the whole user to the delayed method? i.e. User.share_review(current_user, ...) that way it wouldn't be neccasary to call User.find again with the delayed method?
+1
A painful memory while you are exporting 50K above of row in SpreadsheetML
And this occupy one of the worker while in production.
Even you finish export with SpreadsheetML, your customer may can't open it because it is too big and eat up the memory in excel.
I end up writing a rake task and put that in background with spreadsheet gem.
Smaller output and better user experience.
May be I am doing it wrong but that's my experience.
hash = { :key => "value"} can be shorted to hash = { key: "value"} in Ruby 1.9 and up. You are likely running an older version of Ruby.
Actually, koriroys' answer is the better way to go.
It turns out I have xcode 4.3.2 installed but not the command line tools (xcode-> preferences -> downloads). When I ran brew --config it showed my Clang as: 2.1 build 163. After downloading/installing the xcode command line tools brew --config shows Clang: 3.1 build 318.
Then I reinstalled postgresql (brew uninstall postgresql / brew install postgresql) and restarted my server and BAM my postgres command line tools worked...no more segmentation fault.
Answer found on the homebrew github page: https://github.com/mxcl/homebrew/issues/10979
+1 for TorqueBox. An episode deploying TorqueBox to Engine Yard would be fantastic.
better still, how about making
share_review
an instance method? e.g.,current_user.share_review(movie)
(also it should take a movie object, not a movie URL..)I get the following error when I try this on Ubuntu 10.04. Does anyone have any suggestions?
OAuth::Unauthorized (401 Unauthorized):
oauth (0.4.6) lib/oauth/consumer.rb:216:in
token_request'
get_request_token'oauth (0.4.6) lib/oauth/consumer.rb:136:in
.....
Sure. See their documentation about "Configuration and Variables": https://devcenter.heroku.com/articles/config-vars
That is where the constants are stated, but they are not defined there. I think Dominik is on the right track.
Thanks. Any idea how I would define it on Heroku?
Wow thank you @Barwin! I've been wrestling with this for the past 2 days and just couldn't figure out what I was doing wrong. I also had a respond_to block and just needed to pop in a
format.js
. Works like a champ.Perhaps it's a dumb question but imagine that you have 400.000 products
in this chain of wheres conditions (with pagination)
The search execute the first, and then filter with the other where condition so you have a 400.000 products search that kill performances, or am I totally (I wish) wrong?
In this episode it is defined in initializers/devise.rb.
or
Ryan,
It doesn't seem the index updates when you update the data.
Thanks Nik! The GoDaddy coupon code for the $12.99 1-year SSL certs from retailmenot.com still worked (2012-07-13). But during checkout, if you extend it from a 1-year cert to more years, the discount applies to each year! I got a 5-year cert for only $64.95! For once, I'm glad GoDaddy is so crappy.
(If you start with the 5-year cert, then it only applies the discount to the first year though).
Can anyone help me out in this. I am using dynamic fields to generate the ranges. It all working fine but now I have to put some validation over it, and have to do it on Client side. Now I have spent three valuable days to find out the answer but yet not successful. Is there any way to generate my own predecided id to each dynamic text field instead of current date and time? So that I can do the validation using that Id. Or do any one have any better idea? Any type of help will be appreciated. Thanks in advance.
Thank you guys. Both seem promising.
Thanks for the heads up!
I almost fell over too not knowing this. The fact that Rails is reserving a connection I guess part of the 'magic'. I'm wondering now if there's something out I can use to tell Rails not to reserve a connection, or to make controllers explicitly define whether they require a connection...
Sorry if this was posted before
but I would recommend adding --skip-active-record after your rails new MyApp command. You will save a lot of troubles.
Best regards.
I'm getting the same error, also tried it both ways, no luck. Anybody figured it out?
Also, where do you define:
"TWITTER_CONSUMER_KEY" and "TWITTER_CONSUMER_SECRET"
??
Ryan, could we use Koala to to the same job for auth and for get user info, right? What your opinion about Koala x omniauth-facebook?
Thanks.
checking on one of my apps, it seems like the authentication goes through Twitter's secure connection.
Thanks again, Ryan. You say that adding an authentications model is not always necessary to have users authenticate through multiple services. What is the alternative to an authentications model? If there is only one :provider and :uid field, how can you store provider ids and uids from multiple services in the user table?
Thanks.
Lets say I had an app on heroku, with omniauth configured to let users sign in with twitter. Would I need an SSL certificate on my site, or is it safe without one?
No, I don't think so.
Cool, thanks very much. I will try it later.
+1
I am looking for a auto suggest, as a user types in. How do i do that?
I have the same issue, did you resolve this?
https://github.com/cschiewek/devise_ldap_authenticatable
+1 Yes something introducing jRuby would be great for instance I think TorqueBox is great and more people should be looking at it.
HOw would you send the message after that? I can generate the form, but I'd like to see the continuation, where he commented out in the controller.
Thought to use
NotificationsMailer.new_message(@message).deliver
but this gives me error:undefined method
attribute' for Message:Class`This may be due to the fact we dont use activeRecord.
Thanks for the tip house9!
Unfortunately I've never gotten it to work. I uninstalled the pg gem (I had both 0.13.2 and 0.14.0 installed) and re-installed 0.13.2 with:
sudo gem install pg --version 0.13.2 -- --with-pg-config=/usr/local/Cellar/postgresql/9.1.3/bin/pg_config
to no avail. Still getting "segmentation fault: 11" when I get to the psql prompt with "rails db" or with something like "psql -U [username] [db_name]".
My app requires pg 0.13.2.
No, unfortunately
RailsConf this year had a good talk on Backbone
I've been playing with this setting and have run into a bit of a gotcha.
tl;dr - models don't load in rake tasks/migrations - do this:
config.threadsafe! unless $rails_rake_task
or explicitly require the model.The
dependency_loading = false
setting in thethreadsafe!
method means that you won't have access to your models in migrations or rake tasks (ie. db:seed).It's described here this old rails issue and discussed in this article.
For me I had to use the serializer even on a simple model reguardless of it accepting nested attributes. I had a simple table with two fields type and data, where data was hstore and the model had absolutely nothing but validates_presence_of and it would not work until I implemented the serializer, without it, it kept sending it the Raw hash.
Just a note (although it's already mentioned in the episode): The code of the
voted_for?
method is inefficient. The problem is that it actually instantiates an ActiveRecord object which, in this case, is rather unnecessary.Instead of this
you should use the
exists?
method:If you are using scopes or something like that, you can also suffix it to a relation:
In both cases, rather than instantiating an ActiveRecord object, it would just call the connection's
select_value
which is way more efficient.Side note: The
exists?
and its siblingany?
are also helpful for use cases where you want to render a collection or, if it's empty, show the user a message like "No comments yet" or whatever.I've done a mashup of the idea here of sharing templates with railscast 325 but changed to use Handlebars instead of Mustache.
Check it out:
https://github.com/etewiah/sharing_handlebars_templates_in_backbone
I am having a problem though with using exactly the same template on both the client and the server. I explain better in the README. Any comments will be appreciated.
Thanks
I've done a mashup of this rails cast with railscast 295 but changed to use Handlebars instead of Mustache.
Check it out:
https://github.com/etewiah/sharing_handlebars_templates_in_backbone
I am having a problem though with using exactly the same template on both the client and the server. I explain better in the README. Any comments will be appreciated.
Thanks
That's a great article. Thanks for sharing!
This is not an issue specifically with this episode's code. You upgraded from 3.0 to 3.2. Rails already told you what you need to do. Two things:
You did not specify how you would like Rails to report deprecation notices for your development environment, please set config.active_support.deprecation to :log at config/environments/development.rb
You need to remove the
debug_rjs
config option from your environment files as it was deprecated in 3.1 and removed in 3.2.Hope this helps.
This is just amazing...I found the dataTables plugin a while ago and was trying to figure out all out for a few hours. So I come to railscasts to see if Ryan had anything similar, and lo and behold...he's got an episode on the exact plugin I'm using. This has happened so many times it scary - I'm trying to figure out how to use something and Ryan has an episode on exactly what I'm doing. Railscasts is well worth every dime! Thanks for your awesome work, Ryan.
This doesn't work for rails 3.2.5.
I've removed 3.0.0beta from Gemfile and issued bundle install but when I try to run server with:
rails server
I'm getting error:
https://gist.github.com/3098891
It's worth noting that sorting things by
positive votes - negative votes
is not usually what you want to sort by.Is there a reason for not passing the whole user to the delayed method? i.e.
User.share_review(current_user, ...)
that way it wouldn't be neccasary to callUser.find
again with the delayed method?Thanks for saving me a few hours of research to understand the significance of the change.
+1
A painful memory while you are exporting 50K above of row in SpreadsheetML
And this occupy one of the worker while in production.
Even you finish export with SpreadsheetML, your customer may can't open it because it is too big and eat up the memory in excel.
I end up writing a rake task and put that in background with spreadsheet gem.
Smaller output and better user experience.
May be I am doing it wrong but that's my experience.