Ditto, And I'm using Rails 3.1.1. I'm guessing the Rspec folks are going to have to do something one their end. I also suspect that Ryan was aware of this when he filmed this one, because his preferred method for testing is Rspec and yet he didn't mention it in this cast.
Ok... I think I found a fix for rails 3.1. The trick is to keep from using assets. You need the page to be rendered. This may seem hack-ish... I agree... but it does work. This can probably be better refined in the future.
What you need to do, is add an entry in the routes file before the "resources" for products like so:
and proceed as normal. What this does in essence is get Rails to skip using the brand-new asset manager system... and go back to the old-fashioned rendering setup. This is probably a good thing as the index.js is rendered per-request and won't be concat'd together with the other javascript and not minified.
It is much cleaner, but we can take it a little further. If we change the present method to:
ruby
defpresent(object, klass = nil, &block)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
if block_given?
block.arity > 0 ? yield(presenter) : presenter.instance_eval(&block)
end
presenter
end
We can slim our view down to:
html
<% present @user do %><divid="profile"><%= avatar %><h1><%= linked_name %></h1><dl><dt>Username:</dt><dd><%= username %></dd>
...
<% end %>
We'll still have access to the template via h, just need to make it a public method.
a :password_confirmation accessor will be automatically created and available in the view, though validation will not be triggered if password_confirmation is nil.
The problem is caused by preloading ActiveRecord during initialization, not FactoryGirl. You probably are using a gem that does not use ActiveSupport.on_load correctly, or one of your initializers references ActiveRecord::Base. That's bad.
Great stuff as usual Ryan. I'd be very interested in how to handle suspending a recurring payment for X number of months. Use case for that: SaaS company has coupon codes for free months, user already has a subscription with recurring payment but uses a free month coupon, need to skip this month's recurring payment but start again next month.
Looking at railscast.com on github, it has not been committed to since 11.08.2011. Are all this PRO features exluded form the open source railscast repo?
I am guessing that this screencast came from a need on how to implement for the Pro casts. I expect you will find that payment option pretty soon. But I imagine there are other things that need sorting out:
error handling when no funds
cancelling of subscriptions
moving your plan from a credit card to paypal and vice versa. (which I would like to do btw).
the testing, which I think would be an excellent screencast on testing against external services.
The params hash is used to get data that's been posted from a form. You may have seen params being sent back to the browser but that's typically used to re-display a form using data that's already been sent (i.e. when a person has forgotten to input a field).
You can probably set the plan_id using the params hash but it's more work and isn't the idiomatic 'Rails Way.'
I'm gonna try next week to combine with CanCan so i'll let you know - but I see no reason why not - CanCan doesn't care, and I don't see a reason why Sorcery will, as long that you are using the same User model.
If you check out Sorecery Wiki - external login you see that only FB and twitter are currently supported, but if you look at the migrations that are generated by external model, it should be easy to integrate it with another gem, like OmniAuth, then do OpenID authentication & callback from there. It is not pretty and, well, it might brake when either of them changes their DB structure or API, but until Sorcery will support it...
Maybe another idea for an episode is how to save sensitive data (API user/password keys, etc) in production environment, while not disturbing Capistrano deployments etc.?
Yeah, the build method is ActiveRecord magic. Good magic! :)
In your code (@plan_id = params[:plan_id]), the params[:plan_id] is not going to do what you think. The first time the form is shown, params[:plan_id] is going to be nil -- it doesn't exist in the params hash (yet) because it hasn't been set to anything.
It's best to use the build method. It saves you from these bugs that are hard to track down.
Seems to me when I signed up, I looked at the HTML, and he was using Braintree. Ryan, interested in knowing if this is true and if you are planning on converting to stripe for credit cards?
I use Braintree, which I love. But it has two problems, first I pay a monthly fee, second I have to pay another monthly fee for each application I write (since the name on the account has to be "prominently displayed on your site", it has to be the application name not a company name, and hence not sharable across applications).
With this, I get the pricing of PayPal but the customer convenience of entering credit cards directly on my site. Way cool. Can hardly wait to set it up.
I wouldn't make this routes because 2006 can be id article so I won't open this article for example.
or just simple before_create to set max+1 on position
Ditto, And I'm using Rails 3.1.1. I'm guessing the Rspec folks are going to have to do something one their end. I also suspect that Ryan was aware of this when he filmed this one, because his preferred method for testing is Rspec and yet he didn't mention it in this cast.
Ok... I think I found a fix for rails 3.1. The trick is to keep from using assets. You need the page to be rendered. This may seem hack-ish... I agree... but it does work. This can probably be better refined in the future.
What you need to do, is add an entry in the routes file before the "resources" for products like so:
and proceed as normal. What this does in essence is get Rails to skip using the brand-new asset manager system... and go back to the old-fashioned rendering setup. This is probably a good thing as the index.js is rendered per-request and won't be concat'd together with the other javascript and not minified.
Our problem here too: Stack overflow
So, is there another solution for ajax(search, sort, paginate)??
Thanks Ryan! How would you use this with pagination?
Ryan you forgot to add the modified routes file to the show notes. Thanks for these!
@quatermain ... I ran into the same thing. Apparently, "render" is not available to assets in rails 3.1. I'm still poking around for a solution...
+1 for testing the external web services. Even just a taste of it would be cool.
Me too, great work! One of the best I see here.
Hi there, is it possible to embed a video (e.g. youtube video) using redcarpet?
Thank you Ryan,
Can we add to trash box to delete faq links :) with drag? Means Drag and Delete.
May be later, you will add this feature for your casts.
Regards
Revised Railscasts are one of the best things ever. A nice idea taken from the Mythbusters ;]
Thanks for another great episode!
EDIT: It should also be under the Rails 3.1 tag since you were using coffeescript.
You'll get problems when you add more then only one at a time
If that's the only feature you'd want from acts_as_list it seems a better solution.
Rather than using acts_as_list could we just give the position a default value? (i.e. 10000)
how it works with pagination?
It is much cleaner, but we can take it a little further. If we change the
present
method to:We can slim our view down to:
We'll still have access to the template via
h
, just need to make it a public method.A++++ would buy again.
That doesn't work. It still paginate on all the 300 recordss
What's the best way to test a decorator? More specifically, how would you test the following method (in rspec):
When I try the following, I get
undefined method 'number_to_currency' for nil:NilClass
:There's must be some magic going on that sets the view context somewhere. Anyone write decorator helpers for rspec yet?
Me too. I find it strange that there is a screencast about Paypal, but that the option is not yet implemented in to the website.
I love to use Paypal to subscribe to the pro section of this website, because I don't have a creditcard.
Any idea on how to implement massive destroy function?
like checkboxes in front of each entry an a massive destroy button?
Nice Railscast anyway.
thx
Can you help me please?
I have this error:
undefined method render for #<#<Class:0x9e54e54>:0xa860f24>
(in /var/www/final/evidencia02/evidencia/app/assets/javascripts/application.js.erb)
My application.js.erb:
In index.html.erb render 'zoznam' is OK. "zoznam/index" is list of my products with custom sql select.
I hope this (i.e., PayPal) is offered as an option in the near future to purchase a Railscasts Pro subscription!
Struggling too. Did you get anywhere sofar?
You can also use
a :password_confirmation accessor will be automatically created and available in the view, though validation will not be triggered if password_confirmation is nil.
hello ryan,
i'm trying to paginate an array that is returned by this statement?
InstructorRegistration.where(:joins => :user, :order => 'users.last_name')
been tryin few of the options mentioned online but not sure if these are still supported in this version of the gem...
thanks in advance
when i sign in admin panel i get this error.I don't know why?
ArgumentError in Admin::DashboardController#index
wrong number of arguments (2 for 1)
activeadmin (0.3.2) lib/active_admin/arbre/context.rb:15:in
respond_to?'
join'rack (1.3.4) lib/rack/etag.rb:56:in
rack (1.3.4) lib/rack/etag.rb:56:in
digest_body'
call'rack (1.3.4) lib/rack/etag.rb:26:in
rack (1.3.4) lib/rack/conditionalget.rb:25:in
call'
call'actionpack (3.1.1) lib/action_dispatch/middleware/head.rb:14:in
The problem is caused by preloading ActiveRecord during initialization, not FactoryGirl. You probably are using a gem that does not use ActiveSupport.on_load correctly, or one of your initializers references ActiveRecord::Base. That's bad.
Great stuff as usual Ryan. I'd be very interested in how to handle suspending a recurring payment for X number of months. Use case for that: SaaS company has coupon codes for free months, user already has a subscription with recurring payment but uses a free month coupon, need to skip this month's recurring payment but start again next month.
Many thanks and keep up the capital work.
+1
Excellent! So handy. I'm outside the US so Stripe is no use to me. We're woefully behind in terms of SaaS billing options here (Ireland/UK).
Looking forward to the next installment on how to handle failure callbacks. :)
Looking at railscast.com on github, it has not been committed to since 11.08.2011. Are all this PRO features exluded form the open source railscast repo?
second that too
WOW! what a cast! I also want to see this.
Love to see more!
Cancelation, upgrade/downgrade, Error handling.
For those looking for has_many :through counter cache, here's a great post on stackoverflow.
In Rails3.0.5 you are now able to set counter cache to the "linker" model, in your case it will be:
class Meeting_user < ActiveRecord::Base
belongs_to :meeting, :counter_cache => "users_count"
belongs_to :user, :counter_cache => "meetings_count"
http://stackoverflow.com/questions/4700247/counter-cache-has-many-through-sql-optimisation-reduce-number-of-sql-queries
I am guessing that this screencast came from a need on how to implement for the Pro casts. I expect you will find that payment option pretty soon. But I imagine there are other things that need sorting out:
The
params
hash is used to get data that's been posted from a form. You may have seenparams
being sent back to the browser but that's typically used to re-display a form using data that's already been sent (i.e. when a person has forgotten to input a field).You can probably set the plan_id using the params hash but it's more work and isn't the idiomatic 'Rails Way.'
See: ActionController : Parameters
I would love to signup to watch the Pro screencasts, but I only have a Paypal account.
I'm gonna try next week to combine with CanCan so i'll let you know - but I see no reason why not - CanCan doesn't care, and I don't see a reason why Sorcery will, as long that you are using the same User model.
If you check out Sorecery Wiki - external login you see that only FB and twitter are currently supported, but if you look at the migrations that are generated by external model, it should be easy to integrate it with another gem, like OmniAuth, then do OpenID authentication & callback from there. It is not pretty and, well, it might brake when either of them changes their DB structure or API, but until Sorcery will support it...
Maybe another idea for an episode is how to save sensitive data (API user/password keys, etc) in production environment, while not disturbing Capistrano deployments etc.?
Or is it just me? :)
Isn't
params[:plan_id]
passed in through the url when the form is shown?But yea, I get the gist of it.
Yeah, the
build
method is ActiveRecord magic. Good magic! :)In your code (
@plan_id = params[:plan_id]
), theparams[:plan_id]
is not going to do what you think. The first time the form is shown,params[:plan_id]
is going to be nil -- it doesn't exist in theparams
hash (yet) because it hasn't been set to anything.It's best to use the
build
method. It saves you from these bugs that are hard to track down.Either way, you get the gist of what's going on.
Seems to me when I signed up, I looked at the HTML, and he was using Braintree. Ryan, interested in knowing if this is true and if you are planning on converting to stripe for credit cards?
Ahh ok, now I understand. Thanks!
What I would have done was, in the new action, "@plan_id = params[:plan_id]"
Then in the form: <%= f.hidden_field :plan_id, :value => @plan_id %>
To me it seems like less magic is going on by doing it that way.
I use Braintree, which I love. But it has two problems, first I pay a monthly fee, second I have to pay another monthly fee for each application I write (since the name on the account has to be "prominently displayed on your site", it has to be the application name not a company name, and hence not sharable across applications).
With this, I get the pricing of PayPal but the customer convenience of entering credit cards directly on my site. Way cool. Can hardly wait to set it up.
if you are interested in having really fast tests, have a look at corey haines talk: lanyrd.com/2011/gogaruco/shmhw/
I second that. Excellent cast!