Hello,
nice screencast.
As I require full customization functions via the admin webinterface of my Rails app, I cannot afford restarting the server everytime a locale is changed/added. Do you know of a way to disable that or flush the cache at runtime?
A big warning: US only at the beginning would be fine. Outside the US there are no gateways integrated in ActiveMerchent and it is the only program I know that has absolutely no documentation (except from the headers - not a single useful line of a comment). So it is absolutely useless for non-US companies. Even if you don't use PayPal as US company you have to guess what class might do the job and try some options, ... - because of the complete lack of documentation.
As great as your screencasts are (I watched them all) - as useless ist ActiveMerchant.
You use current_cart.build_order.price_in_cents in the controller to setup your response. And then the request cycle goes to paypal and then returns and then im losing the cart_id for the order.
Could someone check that?
You might wanna check your parents folders permissions, as apache is not running with your user permissions, parents folders of your application will at least need execution permission to pass through. Look at "man chmod" for further details on permission.
I'm missing the boat on something. How do I add the shipping information into my orders table when using the express pay. I have the first and last name just like the screen cast. But when I try and add the shipping address or any of the shipping information, its not updating the orders table.
Ryan. Thanks for the great series on Active Merchant and PayPal.
It is my understanding that (like mentioned in episode 145) informations (even more so for sensitive ones) should be gathered in HTTPS... I'm not sure if i missed an episode where the process of doing just that is explained but wouldn't it be a good episode subject otherwise ?
Hey, great blog, lots of useful stuff. I'm a bit of an RoR noob and this site has helped my out a lot. Is a there a simple way to build in a flash message for when the search results come up with nothing?
def index_cache_path
p = ''
p = params[:page] if params[:page] and params[:page] != 1
if logged_in? and current_user.has_role?('super user')
'/admin/people' + p
elsif logged_in?
'/private/people' + p
else
'/public/people' + p
end
end
My problem is that some of my cached index actions respond to an XML format for RSS feeds, but they are unreachable because the action is cached. Is there a way in my index_cache_path to check if a request was XML so I can append 'xml' to the returned cache path?
Let me first say that I find these screencasts extremely useful, even (in fact, particularly) when one partially disagrees with a particular solution proposed by Ryan; he justs puts your neurons in motion.
Here, I question the need of a new class, based on the assertion that "with a class, we can introduce instance variables, while instead with the module we need to pass arguments..".
This is not completely correct; modules can define instance variables (if their name does not clash with existing ones).
And if we created a StarRenderer module:
a) we could define (if needed) instance variables (adding perhaps a prefix sr_) in the module's 'entry point' method.
b) the helper module needing its services would just need to do 'include StarRenderer'.
c) the need of passing 'self' and handling 'method_missing' would simply disappear.
But what if we needed to keep track of 'star results' for different products in the same view (ie, for some reason, they would not be consumed after each calculation)?
Answer: store each result in a virtual attribute in the model (this is 'the class').
Of course, the solution is less elegant than a class; it is also quite lighter, and it would address the 2 problems raised:
a) avoid littering the helper modules with bizarre methods (problem tackled by Ryan).
b) avoid making Rails slower than what already is (see comments above).
I'm having problems using content_for with yield in a rails 2.2.2 project. The content_for is not being rendered. Any one else experiencing problems with content_for in Rails 2.2.2?
Still new to Ruby and Rails and had a quick question. If the purchase fails it goes to a failure page rather than rendering the new action again. Should this be changed? I'm not sure if this is a bad practice or if it was just to simplify it for the screencast.
Nice!
But i have a big question, when paypal returns to the return_url (return to the store) comes with a big url with a lot of variables, how could i make that invisible???
Thanks for your work. Can't wait the end of work day to watch it ;)
However it's 6 screen casts regarding payment gateways. How much more you planning to spend on it, when we will see your screencasts with another rails tips?
Thanks again for the great screen casts, but i had question regarding this one. I understand you establish the habtm relationship between the two models, but i'm not sure how this is being stored in the db.
Everything i read says you need to do something like this product.category.create...
i notice the create action in your controller is the standard create as well as the update, so i'm not sure if this is being done in the Product model?
As a suggestion for future episodes, one thing that is rather near and dear to me right now is that activerecord is actually getting in my way.
What I mean by that specifically is, I want to use native data types in a PostgreSQL database. However, it seems Activerecord is written to make this not only difficult, but more or less impossible without major changes throughout the database layer.
Why would I want to break database agnostic activerecord? Efficiency, both in terms of processing, searching the database, and the ability to use user-defined data types for speed and space improvements.
I'm currently storing around 30 million records in a single table, and without using the cidr and inet types it would be a nightmare.
I've copied this code for my Page model and carefully changed the variables etc however I'm receiving the following error: "Redirect Loop
Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked."
I'm passing an attribute called permalink in the load_page method though:
@current_page = Page.find_by_permalink(id)
Very nice presentation (on a subject that usually is so soporific). I had only a doubt on the view issuing a call to the model (that I had never seen in Rails).
I then saw the answer given by Ryan (post #10): "the @recent_products array had nothing to do with user input. Therefore it belongs in the view more than the controller. Why should the controller care that we want to display the recent products in addition to what the user requested?".
There are a couple of comments here asking about digest encoding of username:password so I just wanted to say that the Rails HTTP authentication library also handles a form of digest encoding - though i am not sure if it conforms to HTTP spec.
To use it, encode 'username:password' in Base64 and put it in the 'authorization' header of the request (which is where basic auth is anyway)
In curl, the line looks like this:
http://gist.github.com/50638
This is really really handy for JavaScript (and iPhone) apps accessing a resource server - especially if you do not have an SSL connection setup and do not want to send login info over the internets in the clear.
I have already implemented ActiveMerchant on my site using the Braintree gateway, but I think a separate screencast on recurring billing using their vault would be especially helpful, even if it is with a different gateway.
BTW: Your code is super CLEAN. Very readable. You always produce the BEST screencasts.
Alas, this seems to be exactly what I need but I can't watch it or download it because the server keeps dropping the connection. Is this just on my end? I'm baffled, and am desperate for HABTM enlightenment.
Thanks for the information about how to add a counter cache to an existing db
However I found that solution a little bit to complex for me. I migrate tables where some inital row values in the db are generated using Model.create in the migration class, which cannot be done with counter caching.
Instead I just made a rake file with the same Model.create calls and that seems to work, if I just generate the values in a correct order.
Any comments on that solution?
I have had trouble with setting up the passenger module (Ubuntu 8.10, apache2, passenger 2.0.6). I did get the 403 error (forbidden, don't have access). In a lot of forumentries there was mentioned it had to do with the permissions. I did solve it by changing the permissions on the var directory (chmod 755 -R /var). But then i get a error with mysqld.sock which somehow needed a 777 permission (chmod 777 -R /var/run). I don't know if this is a good solution because the permissions are messed up this way ...
Great article, especially the layout of the models. Could you do one on how to extend active merchant so that we can all contribute to the code base? I'd love to learn how to write another gateway, or extend AM to do recurring billing or tagged transactions.
Hey Ryan,
This is good stuff but I did notice a problem. It happened when I used attr_accessor myself. At 9:25, you submit the form and validator displays the errors - but it doesn't highlight the problem fields. How can we fix this? It's the one thing that's keeping my application from going into production.
Hello Ryan and guys,
I'm trying to integrate auto_complete feature with complex form (ep. #74) using repeated_auto_complete plug-in but looks like only the first field works.
Does anyone have successfully integrated dynamic fields with auto_completion ?
Thank you!
Found it:
I18n.reload!
Hello,
nice screencast.
As I require full customization functions via the admin webinterface of my Rails app, I cannot afford restarting the server everytime a locale is changed/added. Do you know of a way to disable that or flush the cache at runtime?
Thanks a lot Ryan! But why not ending in great style with a recurring bill episode? :(
Was one of the most important features!
Thanks aniway :)
This tip is powerfull but it's really hard to use it correctly.
Really need a good conception before.
A big warning: US only at the beginning would be fine. Outside the US there are no gateways integrated in ActiveMerchent and it is the only program I know that has absolutely no documentation (except from the headers - not a single useful line of a comment). So it is absolutely useless for non-US companies. Even if you don't use PayPal as US company you have to guess what class might do the job and try some options, ... - because of the complete lack of documentation.
As great as your screencasts are (I watched them all) - as useless ist ActiveMerchant.
I am looking forward on useful screencasts :)
@Stephen Tudor
thanks for the tip in post 78, helped me get this working in Rails2.2.2... great tutorial btw... spot on!!
"[@Matt, @Herbalife] It does work with 2.1. There's a route you have to set - see http://gist.github.com/12391"
I have the same problem as tal@35:
`@raid[attendee_attributes]' is not allowed as an instance variable name
From what I've been able to gather, this might be an acknowledged problem with nesting in partials, but I can't seem to get around it.
FYI I posted a modified version of Ryan's complex form sample app that includes auto_complete behavior; for more info see:
http://patshaughnessy.net/repeated_auto_complete
Just a quick note: the link I pasted just above no longer works; for a modified auto_complete plugin that works in a complex form see:
http://patshaughnessy.net/repeated_auto_complete
I also posted a sample app showing how to use auto_complete for repeated fields, and fixed Sigfrid's issue as well.
You use current_cart.build_order.price_in_cents in the controller to setup your response. And then the request cycle goes to paypal and then returns and then im losing the cart_id for the order.
Could someone check that?
Great series of casts Ryan! VERY helpful!
For the forbidden access issue
You might wanna check your parents folders permissions, as apache is not running with your user permissions, parents folders of your application will at least need execution permission to pass through. Look at "man chmod" for further details on permission.
Hope this helps,
This is exactly what I need, but not every 5 seconds, how can I change the interval?
I'm missing the boat on something. How do I add the shipping information into my orders table when using the express pay. I have the first and last name just like the screen cast. But when I try and add the shipping address or any of the shipping information, its not updating the orders table.
Ryan. Thanks for the great series on Active Merchant and PayPal.
Ryan, Just wanted to thank you for all the recent merchant casts, have been very helpful for setting up my shop. Keep up the good work :)
It is my understanding that (like mentioned in episode 145) informations (even more so for sensitive ones) should be gathered in HTTPS... I'm not sure if i missed an episode where the process of doing just that is explained but wouldn't it be a good episode subject otherwise ?
Great screencasts, btw ! keep up the great work !
thanx
I get an error
news_url failed to generate from {:controller=>"news", :method=>"get", :action=>"show"}, expected: {:controller=>"news", :action=>"show"}, diff: {:method=>"get"}
I add
map.resources :new
to routes.rb
Model name : new
Table name : news
controller name : gamescore
help me please
Hi... it is really nice and good railscasts.. thanks for helping us... i have blogged about this topic..
@ron and @Scott,
Ryan said that he would that in previous episodes! =D
+1 for Recurring Billing!
Hey, great blog, lots of useful stuff. I'm a bit of an RoR noob and this site has helped my out a lot. Is a there a simple way to build in a flash message for when the search results come up with nothing?
--Thanks a bunch
No screencast on recurring billing? That's too bad. Anyway, love the series. Thanks a lot!
Is there a way to integrate activemerchant with offline payment via paypal website payments standard?
For pagination I use:
def index_cache_path
p = ''
p = params[:page] if params[:page] and params[:page] != 1
if logged_in? and current_user.has_role?('super user')
'/admin/people' + p
elsif logged_in?
'/private/people' + p
else
'/public/people' + p
end
end
My problem is that some of my cached index actions respond to an XML format for RSS feeds, but they are unreachable because the action is cached. Is there a way in my index_cache_path to check if a request was XML so I can append 'xml' to the returned cache path?
Let me first say that I find these screencasts extremely useful, even (in fact, particularly) when one partially disagrees with a particular solution proposed by Ryan; he justs puts your neurons in motion.
Here, I question the need of a new class, based on the assertion that "with a class, we can introduce instance variables, while instead with the module we need to pass arguments..".
This is not completely correct; modules can define instance variables (if their name does not clash with existing ones).
And if we created a StarRenderer module:
a) we could define (if needed) instance variables (adding perhaps a prefix sr_) in the module's 'entry point' method.
b) the helper module needing its services would just need to do 'include StarRenderer'.
c) the need of passing 'self' and handling 'method_missing' would simply disappear.
But what if we needed to keep track of 'star results' for different products in the same view (ie, for some reason, they would not be consumed after each calculation)?
Answer: store each result in a virtual attribute in the model (this is 'the class').
Of course, the solution is less elegant than a class; it is also quite lighter, and it would address the 2 problems raised:
a) avoid littering the helper modules with bizarre methods (problem tackled by Ryan).
b) avoid making Rails slower than what already is (see comments above).
I'm having problems using content_for with yield in a rails 2.2.2 project. The content_for is not being rendered. Any one else experiencing problems with content_for in Rails 2.2.2?
Hi Ryan,
Thanks again for the screen cast - very useful.
Still new to Ruby and Rails and had a quick question. If the purchase fails it goes to a failure page rather than rendering the new action again. Should this be changed? I'm not sure if this is a bad practice or if it was just to simplify it for the screencast.
@Bertg, thanks for the correction, I'll update the code in the show notes.
@Igor, This is the last cast on e-commerce for a little while. Expect some more regular episodes over the next few weeks.
Nice!
But i have a big question, when paypal returns to the return_url (return to the store) comes with a big url with a lot of variables, how could i make that invisible???
Hi, Ryan
Thanks for your work. Can't wait the end of work day to watch it ;)
However it's 6 screen casts regarding payment gateways. How much more you planning to spend on it, when we will see your screencasts with another rails tips?
Thanks
Hi Ryan,
thank you very much for another useful and interesting Railscast!
Keep up the good work.
Greetings from Austria,
Udo
When overriding the express_token= method, you set the express_token "attribute" via the self[] method. This is not the best way.
According to the Rails manuals it is better to use write_attribute when overriding an attribute setter (and read_attribute when overriding the getter)
Great cast otherwise ;)
Hey Ryan,
Thanks again for the great screen casts, but i had question regarding this one. I understand you establish the habtm relationship between the two models, but i'm not sure how this is being stored in the db.
Everything i read says you need to do something like this product.category.create...
i notice the create action in your controller is the standard create as well as the update, so i'm not sure if this is being done in the Product model?
Thanks for the help.
John
As a suggestion for future episodes, one thing that is rather near and dear to me right now is that activerecord is actually getting in my way.
What I mean by that specifically is, I want to use native data types in a PostgreSQL database. However, it seems Activerecord is written to make this not only difficult, but more or less impossible without major changes throughout the database layer.
Why would I want to break database agnostic activerecord? Efficiency, both in terms of processing, searching the database, and the ability to use user-defined data types for speed and space improvements.
I'm currently storing around 30 million records in a single table, and without using the cidr and inet types it would be a nightmare.
I aggree. Amazing and helpful. Love Rails ;)
I've copied this code for my Page model and carefully changed the variables etc however I'm receiving the following error: "Redirect Loop
Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked."
I'm passing an attribute called permalink in the load_page method though:
@current_page = Page.find_by_permalink(id)
Thanks,
- Ryan
I was wondering how I would use fixtures to add category/sub category data? Is this even possible using fixtures?
Very nice presentation (on a subject that usually is so soporific). I had only a doubt on the view issuing a call to the model (that I had never seen in Rails).
I then saw the answer given by Ryan (post #10): "the @recent_products array had nothing to do with user input. Therefore it belongs in the view more than the controller. Why should the controller care that we want to display the recent products in addition to what the user requested?".
Irreverent and beautiful!
Thanks for this great screencast. All of them are very helpful!
I cant get the
flash.now[:error] = "Text here"
to work it never shows up. I tried :notice as well but it does not work.
Any advice on this one?
Cheers Juergen
There are a couple of comments here asking about digest encoding of username:password so I just wanted to say that the Rails HTTP authentication library also handles a form of digest encoding - though i am not sure if it conforms to HTTP spec.
To use it, encode 'username:password' in Base64 and put it in the 'authorization' header of the request (which is where basic auth is anyway)
In curl, the line looks like this:
http://gist.github.com/50638
This is really really handy for JavaScript (and iPhone) apps accessing a resource server - especially if you do not have an SSL connection setup and do not want to send login info over the internets in the clear.
G (#30)
Just use "rake test" from the command line at the root of your rails app.
Excellent work! Can't wait for the next.
Great stuff Ryan! Another vote here for SaaS app recurring billing :)
Great screencast, as usual!
I have already implemented ActiveMerchant on my site using the Braintree gateway, but I think a separate screencast on recurring billing using their vault would be especially helpful, even if it is with a different gateway.
BTW: Your code is super CLEAN. Very readable. You always produce the BEST screencasts.
Thanks Ryan!
Chip
Alas, this seems to be exactly what I need but I can't watch it or download it because the server keeps dropping the connection. Is this just on my end? I'm baffled, and am desperate for HABTM enlightenment.
Thanks for the information about how to add a counter cache to an existing db
However I found that solution a little bit to complex for me. I migrate tables where some inital row values in the db are generated using Model.create in the migration class, which cannot be done with counter caching.
Instead I just made a rake file with the same Model.create calls and that seems to work, if I just generate the values in a correct order.
Any comments on that solution?
I have had trouble with setting up the passenger module (Ubuntu 8.10, apache2, passenger 2.0.6). I did get the 403 error (forbidden, don't have access). In a lot of forumentries there was mentioned it had to do with the permissions. I did solve it by changing the permissions on the var directory (chmod 755 -R /var). But then i get a error with mysqld.sock which somehow needed a 777 permission (chmod 777 -R /var/run). I don't know if this is a good solution because the permissions are messed up this way ...
Great article, especially the layout of the models. Could you do one on how to extend active merchant so that we can all contribute to the code base? I'd love to learn how to write another gateway, or extend AM to do recurring billing or tagged transactions.
Thanks!
Hey Ryan,
This is good stuff but I did notice a problem. It happened when I used attr_accessor myself. At 9:25, you submit the form and validator displays the errors - but it doesn't highlight the problem fields. How can we fix this? It's the one thing that's keeping my application from going into production.
Thanks!
Hello Ryan and guys,
I'm trying to integrate auto_complete feature with complex form (ep. #74) using repeated_auto_complete plug-in but looks like only the first field works.
Does anyone have successfully integrated dynamic fields with auto_completion ?
THANKS