Thanks for the wonderful web cast. I am using daemon, instead of cron job, to periodically rebuild sphinx delta index. The reason is that my data update very frequently and I want to udpate the delta index every 10 seconds or so whereas cron job can not be scheduled by seconds.
I tried to run rake command in the daemon to rebuild index for sphinx. But the rake command is never successfully executed. The source code is as following. I just don't know what is going on.
You mentioned in http://railscasts.com/episodes/127-rake-in-background that rake task is quite resource-consuming for frequent using. So I am wondering whether I am even in the right track or not.
Thank you very much. Any suggestion is appreciated.
jQuery vs Prototype argument... it really comes down to personal preference. I much, much prefer jQuery due to the far superior documentation of the library compared with prototype. Devs get spoilt with jQuery, it's far too easy when reading the examples.etc. I found with the prototype documentation I still had to piece things together in my head before I could write solutions. That's just my view of it, others may have had a different experience.
Ryan!!! Couldn't you have done these series one month ago!? eheh... sorry, but I spend more than one week struggling with paypal to do a subscription system, at the beginning I thought using active merchant but they don’t have good documentation, so I started creating a gem to deal with paypal standard payments and IPN for subscriptions.
Funny thing when we get it working we changed our minds and we end up to use active merchant and checkout express, even so we had to extend AM because it doesn’t deal with subscriptions for default. Using that second API we don't have to rely on the IPN system and we have more controller over the user data and transactions, it applies better to our web site goal.
In any case if anyone want a simple solution you can use my code or gem created for subscription but easy adaptable to normal payments(you only have to delete code) answering Michael Schueri I use https and all the paypal security procedures to validate de IPN origin. So my code is rely simple, customizable and it has 10 times more lines of test code than the real one.. so I think it's well tested and secure to use! For a matter of fact I love railscasts and believe this is going a be a quality series that's why I'm frustrated, one month ago could have saved me lots of work. ;)
I have a relationship many to many between two objects "factura" and "factura_producto". I've implemented this code to update many record into "factura_producto" table.
This send the following error:
Rendered orden/_factura_producto (0.00848)
Rendered orden/_factura_producto (0.00238)
Rendered orden/_factura_producto (0.00243)
Rendered orden/_factura_producto (0.00614)
Rendered orden/_factura_producto (0.00221)
Rendered orden/_factura_producto (0.00219)
Rendered orden/_factura_producto (0.00788)
Rendered orden/_factura_producto (0.00254)
Rendered orden/_factura_producto (0.00239)
Rendered orden/_factura_producto (0.00194)
Rendered orden/_fields (0.13827)
Completed in 0.21036 (4 reqs/sec) | Rendering: 0.14042 (66%) | DB: 0.03088 (14%) | 200 OK [http://localhost/orden/edit/1]
Conflicting types for parameter containers. Expected an instance of Hash, but found an instance of Array. This can be caused by passing Array and Hash based paramters qs[]=value&qs[key]=value.
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_ext/cgi_methods.rb:204:in `type_conflict!'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_ext/cgi_methods.rb:168:in `container'
How can we add additional fields to the category object on the fly?
I mean if if the category doesn't exist based on the info that user typed in the autocompleter field, I would like to show Category form with name and description fields in place of autocompleter field and the category name should be prepopulated with the value that the user entered in the autocompleter field. Once the product is submitted along with the category name and description information, product should be either created/saved with category assigned to it.
Would appreciate it if somebody could point me to any existing resource that achieves this functionality. Thanks in advance.
From this screencast it looks almost too easy to interface with PayPal. Actually, I think it does look too easy, as you're sending all the data in plain sight and unprotected.
You really should not send your customers purchase detail unencrypted over the wire. So, better use HTTPS.
The other way round, you don't want customers to be able to tamper with amounts without your app or PayPal noticing it. Therefore, don't forget to add hashes for integrity checking.
Then, when it comes to being notified by PayPal that the payment has been processed, you need to make sure that the notification has indeed been sent by PayPal and not been faked by someone else.
Also, anyone who tries to implement something like this ought to keep in mind all the possible failure conditions and how they affect the workflow.
I don't know the PayPal API, but I'm pretty sure that they support everything that's needed to make payment secure. It is not rocket science to write an equally secure client, however, it is rather more time consuming than pasting together a URL.
In general, if at all possible, I strongly recommend to use a solution (plugin, gem) that does the job and already has some traction in the community.
@grosser, an episode or two an ActiveMerchant is planned later on in this series.
@Stephen, thanks! I never knew about to_query. It looks like calling that on the hash will do just what we need (along with proper escaping). I'll update the code.
PLEASE read your amended Paypal User Agreement! Paypal (owned by ebay) can now withhold users funds for 21-180 days at Paypal's "sole discretion"!!! Users are being caught in this trap at alarming rates! We can all thank ex-ebay CEO, Whitman and current CEO, Donahoe, for their "Disruptive Innovation" SCHEME against users for many such detrimental changes.
To read what the users are REALLY experiencing, search the internet for
"Ebay Stockholders and Sellers Calling For Immediate Termination of John Donohoe CEO Petition" (at petitiononline).
To learn about their own employees experiences with such POOR management, go to glassdoor and type in ebay.
I know this is an old cast, but I just wanted to point everyone towards a great little plugin I found after watching this.
http://github.com/emk/safe_erb/tree/master
it raises an exception anytime content is displayed to the screen without being escaped with "h". Helped me find a few vulnerabilities in my current project.
Even it's an old one, it's a great one, and as always with every of my projects you seem to read my mind. Had a problem, found your screencast. Keep on going. Thx.
Ryan - if you did not want to use create.js, and wanted to call another file instead, how would you do it? The screencast alluded to the possibility, but I haven't figured out how. Thanks!
@Mike
Your answer may seem easier but you missed that with your sentences you end up making 2 queries while it was originally only one.
By the way, I'd like to understand it too, PhilT! You can give a try to a really nice pluggin about writing "rubyish" queries: Squirrel (http://thoughtbot.com/projects/squirrel)
Replying to myself, an alternative method might be to move the scoped index action to the articles controller, like so: http://pastie.org/341271 (haven't checked to see if this works).
I too am interested in how you can elegantly implement the 2 different types of index action (/comments and /articles/1/comments).
The method outlined in http://pastie.org/333938 is fairly neat, but requires you to either have lots of logic in your view template, or override the template selection with a render call (see http://pastie.org/341264)
Because this is such a common problem, it'd be nice if there was a standard pattern for achieving this.
It's probably better to use double quotes around the state name in the js file since a state name might contain a single quote. Ex. "Provence-Alpes-Cote d'Azur"
In dynamic_states.js change '<%=h state.name %>' to "<%=h state.name %>"
@Mike
I think you missed the idea.
The extra nested hash in conditions helps you specify WHERE conditions on the associations you've joined.
I can't remember a good example right now, but quite often you need to join two or more associations, where such an addition to Rails serves to beautify code.
I am having the same problem. My guess is that something has changed in the newer version of Rails since this screencast was created. I don't know what it is but you are not alone.
here is something that you might find useful. This is attempt to make routes.rb more dynamic. routes.rb gets dynamically generated without need of server restart or redeploy.
Chetan: you can't do OR conditions across fields and attributes in Sphinx, nor can you check if a field is blank that simply. If you'd like to discuss the problem further, please visit the google group:
Relational databases and the SQL language used to access them have no concept of "last" without an ordering. Just in case it's not clear (as it wasn't clear to me) in the Rails world, :last means "with the highest id".
@Ryan please embrace censorship and remove some of the irrelevant (putting it politely) stuff.
@Jay up above has a good point which I am also struggling with.
Also there are a number of folks here that appear to be contributing but post a load of cryptic stuff.
If one means to help they should just help if you feel it impinges on your intellectual property then don't clog things up and force endless scrolling.
Video works for me embedded in Firefox on Ubuntu 8.10 after it installed some gstreamer plugins.
After doing update_rubygems on Ubuntu 8.10 I lost all my installed gems (gem list --local) although looking in /var/lib/gems/1.8/bin and .../gems I can see they're there.
Updating rubygems has always been a fun exercise, huh?!
Ryan: What would you put in the index action of the comments controller to handle whether or not an article ID has been passed? I've seen a number of ways of handling this and nothing really seems all that elegant. It'd be nice to see your take on it.
Hi Ryan,
Thanks for the wonderful web cast. I am using daemon, instead of cron job, to periodically rebuild sphinx delta index. The reason is that my data update very frequently and I want to udpate the delta index every 10 seconds or so whereas cron job can not be scheduled by seconds.
I tried to run rake command in the daemon to rebuild index for sphinx. But the rake command is never successfully executed. The source code is as following. I just don't know what is going on.
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= "development"
require File.dirname(__FILE__) + "/../../config/environment"
$running = true
Signal.trap("TERM") do
$running = false
end
while($running) do
time_start = Time.now
system "/usr/local/bin/rake thinking_sphinx:index:delta &"
time_finish = Time.now
time_span = time_finish - time_start
ActiveRecord::Base.logger.info "/usr/local/bin/rake thinking_sphinx:index --- #{time_span} seconds. \n"
sleep 10
end
You mentioned in http://railscasts.com/episodes/127-rake-in-background that rake task is quite resource-consuming for frequent using. So I am wondering whether I am even in the right track or not.
Thank you very much. Any suggestion is appreciated.
cheers
--
Canvas
Ooh, a Railscasts cliffhanger
jQuery vs Prototype argument... it really comes down to personal preference. I much, much prefer jQuery due to the far superior documentation of the library compared with prototype. Devs get spoilt with jQuery, it's far too easy when reading the examples.etc. I found with the prototype documentation I still had to piece things together in my head before I could write solutions. That's just my view of it, others may have had a different experience.
great information!
Is this still the proper way to do nested forms?
Does it matter how many levels your nested form is?
hi there!
Ryan!!! Couldn't you have done these series one month ago!? eheh... sorry, but I spend more than one week struggling with paypal to do a subscription system, at the beginning I thought using active merchant but they don’t have good documentation, so I started creating a gem to deal with paypal standard payments and IPN for subscriptions.
Funny thing when we get it working we changed our minds and we end up to use active merchant and checkout express, even so we had to extend AM because it doesn’t deal with subscriptions for default. Using that second API we don't have to rely on the IPN system and we have more controller over the user data and transactions, it applies better to our web site goal.
In any case if anyone want a simple solution you can use my code or gem created for subscription but easy adaptable to normal payments(you only have to delete code) answering Michael Schueri I use https and all the paypal security procedures to validate de IPN origin. So my code is rely simple, customizable and it has 10 times more lines of test code than the real one.. so I think it's well tested and secure to use! For a matter of fact I love railscasts and believe this is going a be a quality series that's why I'm frustrated, one month ago could have saved me lots of work. ;)
Hi all,
I have a relationship many to many between two objects "factura" and "factura_producto". I've implemented this code to update many record into "factura_producto" table.
This send the following error:
Rendered orden/_factura_producto (0.00848)
Rendered orden/_factura_producto (0.00238)
Rendered orden/_factura_producto (0.00243)
Rendered orden/_factura_producto (0.00614)
Rendered orden/_factura_producto (0.00221)
Rendered orden/_factura_producto (0.00219)
Rendered orden/_factura_producto (0.00788)
Rendered orden/_factura_producto (0.00254)
Rendered orden/_factura_producto (0.00239)
Rendered orden/_factura_producto (0.00194)
Rendered orden/_fields (0.13827)
Completed in 0.21036 (4 reqs/sec) | Rendering: 0.14042 (66%) | DB: 0.03088 (14%) | 200 OK [http://localhost/orden/edit/1]
Conflicting types for parameter containers. Expected an instance of Hash, but found an instance of Array. This can be caused by passing Array and Hash based paramters qs[]=value&qs[key]=value.
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_ext/cgi_methods.rb:204:in `type_conflict!'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/cgi_ext/cgi_methods.rb:168:in `container'
How can we add additional fields to the category object on the fly?
I mean if if the category doesn't exist based on the info that user typed in the autocompleter field, I would like to show Category form with name and description fields in place of autocompleter field and the category name should be prepopulated with the value that the user entered in the autocompleter field. Once the product is submitted along with the category name and description information, product should be either created/saved with category assigned to it.
Would appreciate it if somebody could point me to any existing resource that achieves this functionality. Thanks in advance.
-Satynos
From this screencast it looks almost too easy to interface with PayPal. Actually, I think it does look too easy, as you're sending all the data in plain sight and unprotected.
You really should not send your customers purchase detail unencrypted over the wire. So, better use HTTPS.
The other way round, you don't want customers to be able to tamper with amounts without your app or PayPal noticing it. Therefore, don't forget to add hashes for integrity checking.
Then, when it comes to being notified by PayPal that the payment has been processed, you need to make sure that the notification has indeed been sent by PayPal and not been faked by someone else.
Also, anyone who tries to implement something like this ought to keep in mind all the possible failure conditions and how they affect the workflow.
I don't know the PayPal API, but I'm pretty sure that they support everything that's needed to make payment secure. It is not rocket science to write an equally secure client, however, it is rather more time consuming than pasting together a URL.
In general, if at all possible, I strongly recommend to use a solution (plugin, gem) that does the job and already has some traction in the community.
@grosser, an episode or two an ActiveMerchant is planned later on in this series.
@Stephen, thanks! I never knew about to_query. It looks like calling that on the hash will do just what we need (along with proper escaping). I'll update the code.
BEWARE OF PAYPAL!
PLEASE read your amended Paypal User Agreement! Paypal (owned by ebay) can now withhold users funds for 21-180 days at Paypal's "sole discretion"!!! Users are being caught in this trap at alarming rates! We can all thank ex-ebay CEO, Whitman and current CEO, Donahoe, for their "Disruptive Innovation" SCHEME against users for many such detrimental changes.
To read what the users are REALLY experiencing, search the internet for
"Ebay Stockholders and Sellers Calling For Immediate Termination of John Donohoe CEO Petition" (at petitiononline).
To learn about their own employees experiences with such POOR management, go to glassdoor and type in ebay.
I build a websize like yours.
http://rubycnrails.cn
It just for Chinese.
I have many problems want to ask you?
Could you mail me?
A little Active Support for your key-value mapping: "Object#to_query".
Thank goodness! This series was long overdue. Thanks, Ryan!
i recommend active_merchant for those kind of payment processing, makes life easier / more robust / secure
www.activemerchant.org
Hi Ryan,
Thanks for the screencast.
You kept my trust on you by giving long screencast.
Now again I am waiting eagerly for next monday.
Thanks for the great shows!
Thank Ryan,
Waiting for the CC's payment episodes!
Thanks Ryan,
Just what the doctor ordered for a fresh Monday morning! I think i mind control you over the week for the stuff i'll need at the end of it.
Cheers,
Aditya
I know this is an old cast, but I just wanted to point everyone towards a great little plugin I found after watching this.
http://github.com/emk/safe_erb/tree/master
it raises an exception anytime content is displayed to the screen without being escaped with "h". Helped me find a few vulnerabilities in my current project.
Even it's an old one, it's a great one, and as always with every of my projects you seem to read my mind. Had a problem, found your screencast. Keep on going. Thx.
Thanks Ryan, your Railscasts are fantasic!
Why do I get ActionView::TemplateError (undefined method `each' for false:FalseClass) when I use <%= t 'hello' %> in a view??
Love the Pref pane and the logging insight!
Ryan - if you did not want to use create.js, and wanted to call another file instead, how would you do it? The screencast alluded to the possibility, but I haven't figured out how. Thanks!
Did you know, that content_tag is more slover than static tag definition like "<div>#{@hello}</div>"?
@Mike
Your answer may seem easier but you missed that with your sentences you end up making 2 queries while it was originally only one.
By the way, I'd like to understand it too, PhilT! You can give a try to a really nice pluggin about writing "rubyish" queries: Squirrel (http://thoughtbot.com/projects/squirrel)
Great screencast, really great!!! The comments also are very useful.
Thanks guys.
Replying to myself, an alternative method might be to move the scoped index action to the articles controller, like so: http://pastie.org/341271 (haven't checked to see if this works).
I too am interested in how you can elegantly implement the 2 different types of index action (/comments and /articles/1/comments).
The method outlined in http://pastie.org/333938 is fairly neat, but requires you to either have lots of logic in your view template, or override the template selection with a render call (see http://pastie.org/341264)
Because this is such a common problem, it'd be nice if there was a standard pattern for achieving this.
It's probably better to use double quotes around the state name in the js file since a state name might contain a single quote. Ex. "Provence-Alpes-Cote d'Azur"
In dynamic_states.js change '<%=h state.name %>' to "<%=h state.name %>"
i get events, and group_by start_date it shows the the order of day like saturday, friday, trusday ..., How i get the data as reverse order?
Like this!
:select => 'DISTINCT tracks.*',
:joins => [{:song => :stores}, {:song => :genres}],
:conditions => {:instrument_id => instrument_ids, :stores => {:id => id}, :genres => {:id => genre_ids}}
Needed to make a simple search feature work.
What I don't understand is why this works and yet :include doesn't. If you try to use includes you get outer joins but it also ignores the select.
@Mike
I think you missed the idea.
The extra nested hash in conditions helps you specify WHERE conditions on the associations you've joined.
I can't remember a good example right now, but quite often you need to join two or more associations, where such an addition to Rails serves to beautify code.
Or even better :
clothingProducts = Category.find_by_name('Clothing').products
Mike
I guess if you work with Rails everyday all day that :
>
Product.all(:joins => :category, :conditions => {:categories => {:name => 'Clothing'}})
makes sense, and is "easy" to remember ? ;)
This seems a lot easier to me :
clothing=Category.find_by_name("Clothing")
prods=Clothing.products
I thought that was one of the purpoes for ActiveRecord, i.e. to eliminate having to remember cryptic syntax ?
What does the first syntax do that the second one doesn't?
Mike
Thanks Ryan for your screencast.
Have you or anyone tried using starling (and workling) on Windows?
I have currently installed starling-starling gem (0.9.9) on my Windows XP machine.
I am able to start Starling. However, I get a Rubygems Load Error when I attempt a require 'starling'.
Have you or anyone else encountered this problem with starling-starling gem on Windows?
Thanks,
Sam
hey brian,
I am having the same problem. My guess is that something has changed in the newer version of Rails since this screencast was created. I don't know what it is but you are not alone.
here is something that you might find useful. This is attempt to make routes.rb more dynamic. routes.rb gets dynamically generated without need of server restart or redeploy.
Chetan: you can't do OR conditions across fields and attributes in Sphinx, nor can you check if a field is blank that simply. If you'd like to discuss the problem further, please visit the google group:
http://groups.google.com/group/thinking-sphinx
Relational databases and the SQL language used to access them have no concept of "last" without an ordering. Just in case it's not clear (as it wasn't clear to me) in the Rails world, :last means "with the highest id".
How can i add mrss feeds?
for example
<media:content url="file.mp3" type="audio/mpeg" duration="33" />
how do i add the ":content" to the media tag?
@Ryan please embrace censorship and remove some of the irrelevant (putting it politely) stuff.
@Jay up above has a good point which I am also struggling with.
Also there are a number of folks here that appear to be contributing but post a load of cryptic stuff.
If one means to help they should just help if you feel it impinges on your intellectual property then don't clog things up and force endless scrolling.
Hey Ryan!
small and sweet screencast!!!
next week I will expect longer screencast ;)
Enjoy the holidays for now.
Thank you,
hash in conditions is useful as well ;)
Nice tips. You don't need to apologize for anything Ryan. We appreciate every screencast you put out.
no one has any info about: Error reading HTTP body: #<RuntimeError: Socket read returned insufficient data: 10379>??
How to query a virtual attribute?
Model.find(:all, :order=>'name')
where the 'name' attribute is not found in the model, its a virtual attribute.
Please help!
Oh I see. It's because I was running as sudo instead of root and it's looking in ~/.gem now
Video works for me embedded in Firefox on Ubuntu 8.10 after it installed some gstreamer plugins.
After doing update_rubygems on Ubuntu 8.10 I lost all my installed gems (gem list --local) although looking in /var/lib/gems/1.8/bin and .../gems I can see they're there.
Updating rubygems has always been a fun exercise, huh?!
Ryan: What would you put in the index action of the comments controller to handle whether or not an article ID has been passed? I've seen a number of ways of handling this and nothing really seems all that elegant. It'd be nice to see your take on it.
Thanks!