RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Ok, if an invitation is required to sign up, how do you sign up an initial, "admin" user?

I ran the rake db:fixtures:load, and I looked at the rake source, but the passwords are not listed, so I have no idea what they are ;)

I tried putting an invitation token called 'test' into the invitations table, then tried http://localhost/signup/test.

I get :# invitation is required
# Invitation has already been taken

I dumped the params, and the invitation_token is blank, so it doesn't seem to be getting picked up from the browser url.

I'm running rails 2.2.2.

Any ideas ?

Mike

Avatar

<h1>Register</h1>

<% form_for(@user) do |f| %>
  <p>
    Full Name(Separated by a space)<br />
    <%= f.text_field :full_name %>
  </p>
  <p>
    Password<br />
    <%= f.text_field :full_name %>
  </p>
  <p>
    <%= submit_tag 'Register' %>
  </p>
<% end %>
<%= link_to 'Back', users_path %>

Avatar

class User < ActiveRecord::Base
  def full_name
    [first_name, middle_initial_with_period, last_name].compact.join(' ')
  end
  def middle_initial_with_period
    " #{middle_initial}. " unless middle_initial.blank?
  end
  def full_name=(name)
    split = name.split(' ',3)
    self.first_name = split.first
    self.last_name = split.last
    self.middle_initial = split[1]
  end
end

Avatar

@Dan: it exists and it is compulsory for validating a purchase! It's just that Ryan didn't get into that yet. I guess he'll talk about it in the next episode.

At this stage of the app you still cannot mark a cart as being purchased/paid.

FYI Paypal provides on their developer website, a Ruby on Rails app in which you can dive in to understand the payment process, but beware it requires a lot of cleaning up.

Avatar

Dave A. and Ryan S.,

Remove the formatted keyword from all the lines that use the formatted_article_url helper

example: xml.link article_url(article, :rss)
instead of xml.link formatted_article_url(article, :rss)

Avatar

Great screencast, Ryan!

Paypal kind of bums me out. I dislike the idea of ipn. For MassPay transactions, I really wish there was a query/request you could send to get the status of payment, but unfortunately I haven't been able to find it.

Avatar

@Hamza, I plan to cover ActiveMerchant in future episodes.

@zero0x, right, this is one of the security issues I plan to cover in the next episode.

@Josh, that sounds great. I don't plan to cover Google Checkout in this series, but maybe if there's enough demand I'll make an episode for it later.

@Patrick, using ActiveRecord's validations on a non-database backed model can be difficult. I am delaying talking about this issue until Rails has some better support for this built in. But in the meantime you may want to check out some external validation plugins. Sorry I don't know of the best one off the top of my head.

I personally do not run into this issue because I prefer to keep a record of user input. So, every model that has a decent size form is backed by a database.

Avatar

For Rails 2.2:

# config/initializers/time_formats.rb

Time::DATE_FORMATS[:my_format] = "%B %Y"

Avatar

Big thanks. I was looking all the time for this. Greetings, Jacko

Avatar

Was wondering if anyone else had seen or heard of this problem or anything similar.

I placed 1000 messages onto the queue. In a matter of seconds they all get taken off the queue.

I have a sleep 5 and a logger.info "message" in the worker class. I do not see "message" 1000 times though. I might see it a couple of times but that is it.

Anyone else know what could be going on? (this only happens on my redhat box. on my macbook, it works fine)

starling 0.9.9
workling 0.4.2.2
fiveruns-memcache-client
ruby 1.8.7
rails 2.1.2

Avatar

hey Ryan,

Firstly, thanks for all the hard work you put in to help the community. We really do appreciate it. I am having the same issue as brian and Jonathan. I have a

modelX

has_one :ownership
has_one :user, through => :ownership

I tried following the tutorial and noticed recommendations to try the ownership.build(<new instance based on passed in params>) approach.

So my call in the model looks like this:

def ownership_attr=(ownerships)
  ownerships.each do |owner|
    ownership.build(:o => Ownership.new(owner)
  end

Then when I hit the create button I get an exception nil.build. I have tried Ownership.create!(params passed in) but that leaves the ModelX_id to nil.

Help is greatly appreciated.

Thanks again

Avatar

Hey Ryan:
Would you mind addressing how to validate non-model backed form components? I'm specifically talking about forms where you use a model to save stuff like the customer's name and phone number, but you don't want to save sensitive data like their credit card number to the database for security reasons.

The same question was raised in a different context by creatop in the comments of Episode 37: "Nice, but what about more complicated non-model forms with many fields with validation required?"

It seems like a pretty common scenario to me - but for some reason there is absolutely no documentation on it (or if there is, I've wasted the last five hours for nothing...haha).

Avatar

Things become really complicated when trying to add an autocomplete functionality to a dynamic form field. I started a thread here http://railsforum.com/viewtopic.php?pid=83963#p83963

Avatar

Good episode. Is there a way to include extra parameters in the URL while still keeping with REST? For example, if you have a resource Place but would like in include the country ID in the URL (ie, /places/us/123-new-york or /places/us/page/:page_number).

Avatar

Hey Ryan,

I have taken what you have done here (great workup, by the way!) and have translated it to use Google Checkout using the google4r-checkout gem. It is really great! Let me know if you want me to pastie you the source for a Railscast episode in this series :)

Thanks again!

Avatar

I tried out the code,

It works great!

But there is one problem.

I am in the middle of making a Scavenger Hunt app, and there is teams and tasks and they have a HABTM relationship to each other.

I did everything like you said/showed but when I try to add a task to one of the teams when that task is already on another team then it won't work.

It has something to do with the ID and it not being unique.

It's passing the same number for the ID in the joining table and for the 'task_id' column in it, so it gets an non-unique ID when another team completes that task.

Is there like a way to make it auto-increment the ID column

PLEASE HELP!!! I'm new to this and it makes no sense coming from a PHP background.

Thank You

Avatar

Hello!

Thanks for this tutorial, it is really great, but i am somehow stuck on the serialize part....

In a LOG i can see i get all the information from PayPal, but serialize is somehow failing.

Anyone else with a same problem?
What could be a trick?

Thanks

Avatar

You are the BEST!!!

Avatar

Happy New Year, Ryan!

Thank you for all your work this year.
Please, continue on the next year.
Thanks thanks thanks!!!

Avatar

Great Tutorial Again!

@Ryan:
If you continue to support us with this high quality screencasts, I'll maybe use the learned things to open my own business ;)

Happy New Year to everyone! (not yet but in a few hours ;) )

Avatar

I must say, that Pat's solution for multiple fields is really cool!

Avatar

Ryan President ! :)

Avatar

Found the answer to my own question.

In Rails 2.2.2 TimeZone lives in ActiveSupport, so I had to change the parameter to:

ActiveSupport::TimeZone.us_zones

Avatar

I'm getting the following error on my view:
"uninitialized constant ActionView::Base::CompiledTemplates::TimeZone"

If I remove the TimeZone.us_zones parameter from the selection list the error goes away -- but then I get all time zones in the list. Any idea what could be wrong?

I'm using Rails 2.2.2 so maybe there's an issue with this version.

Avatar

No questions, no suggestions, no complaints, just THANKS!

Avatar

Hi Ryan,

Paypal's Order Management integration guide says you need to use a "shared secret" or a "postback". I did not see you use either.

See page 26th of the guide: "After your server receives an Instant Payment Notification, you must confirm that the notification is authentic. This is known as notification validation."

Can you comment on this? Am I missing something?

Thanks,

John

Avatar

Hi there,
Love the podcasts...
Way back a year ago (items 10 and 11 above) you mention stubbing out the current_user.

Could you please elaborate on that.

What do I do if I have an rspec generated spec (from the scaffold generator) for a controller, which works fine (all the tests pass) but now I want to make the entire controller require a login. (using a before filter)

[Note: I'm using restful authentication, as provided in bort. See http://github.com/fudgestudios/bort/tree/master]

Do I need to re-write all of the tests that pass (but assume no login is required) or is there an easy way to make the whole set of tests act as though a user is logged in.

Then, I assume I just need to write a test or two which verifies correct behavior when a user is NOT logged in. Which probably just confirms a redirect.

Thanks,
John Schank

Avatar

Hey,

I'm working on an e-shop (php but nevermind), and wanna ask something.

Is it safe enough to check the notification for the amount paid to ensure that payment was not tampered?

Avatar

I think recurring billing would be an interesting and useful topic. I know that certain payment gateways support it, but it can be complicated. You would need a background task to scan periodically and make charges...

Thanks Ryan and keep up the good work.

Avatar

David,
I'll respond to you by email.

I'm very appreciate Ryan, and don't want to start flame here.
Thanks.

Avatar

It is interesting how other people do these kind of things.

However I am still a bit unsure why you are not using ActiveMerchant ?

Don't you find it makes things easier ?

Thanks, and keep up the good work!

Hamza

Avatar

To test this locally you could quite easily setup a dynamic dns to point a public domain name to your local environment, such as dyndns.

I've done that on a couple of occasions when working with external services which need to hit my machine as part of the applications natural processes.

Avatar

It's annoying to wait until next episode for production use! :-)

Thanks, Ryan!

Avatar

For those concerned about security and payment notification, I plan to address this in future episodes in this series. Stay tuned!

Avatar

This tutorial covers the basics. It is not meant to be a full, complete solution as mentioned in the beginning. I'm sure Ryan will add more in using Encrypted Payments and verifying things like Paypal IPN.

Avatar

I've been using this method for a while, but I think I've found a problem with it.

If you delete all of the tasks in one fell swoop, by the looks of development.log the existing_task_attributes set of fields isn't serialised at all. This means that when update_attributes is called, the existing_task_attributes= method in the Project model isn't called, hence none of the tasks are removed.

This seems a little crazy, but the problem is very real for me!

Avatar

Great screencast, Ryan. :)

@Edgar G. You must have missed the part about this being an introduction to payment processing with PayPal. As an introduction, it does a good job of illustrating how the system works. I'm sure Ryan will address some of the security issues later on in the series.

Avatar

fantastic screencast ryan! thanks for this and all the others.

Avatar

Very helpful! Thank you!

Avatar

@Memiux: yes it matters. If people start playing with the amount of money passed to Paypal, it will become a huge pain for the admin to track manually who has paid the correct amount and who didn't.

The potential cheaters can claim that they didn't do it on purpose.

Either use encrypted method or don't process online payment.

Avatar

@Edgar G (18), It doesn't matters, there's not sensitive information

Avatar

This episode is useless as the data is sent over to Paypal using the unencrypted method.

Avatar

Great RailsCast, thanks!
[pt] Grande Railscast, obrigado!

Avatar

@aman: http://pastie.org/346594

Avatar

Hi,

can you please give a quick tip on how to add make a current navigation menu link standout from the others. e.g. if i want to make the background color change by appling a class on the current link, how to do it. Is there a way to achieve this without overly complecating stuff, as i just have couple of static links.

Avatar

I built another rake task and tried it in the daemon. But it dose not
work neither. It seems that the daemon just dose not like any rake
tasks in it for some reason. It really drives me crazy.

Avatar

Hi Ryan,

I tried command
" system 'rake thinking_sphinx:index' " in IRB and controller action, it worked in both cases. It seems that it dose not work only in the daemon. Any ideas? Thanks.

Cheers
--
Canvas

Avatar

There's also a 'deploy:cleanup' task that is really useful for limiting the number of releases:

http://pastie.org/343030

Avatar

Ryan,

Off topic, is there a way to download / clone just the episode-141 "tree" using git?

Learning git is almost as complex as Ruby / Rails :)

Otherwise a "git clone git://github.com/ryanb/railscasts-episodes.git" will clone all of the episodes.

Mike

Avatar

Thanks for this screencast, I'm all geared up now on my web site for next Christmas :)

To the PayPal basher above, you don't really know much about the internet do you?

When you submit a form, anyone submitting the form can change any of the values...its up to you as the merchant to make sure the order amount is correct before shipping it once you receive the payment in PayPal.

Clearly, only a fool would go ahead and ship $500 worth of stuff of which they only received $1.

@Ryan, sorry to even engage that guy...