RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

You save my day. Thanks.
using Ruby 1.9.3 & Rails 3.2.14.

Avatar

Does this work with optimistic locking and a lock_version column set up? I'm getting:

ActiveRecord::StaleObjectError

ruby
class VersionsController < ApplicationController
  def revert
    @version =  PaperTrail::Version.find(params[:id])
    @version.reify.save!
    redirect_to :back, :notice => "Undid #{@version.event}"
  end
end

Problem is on line 4

Avatar

Simple Form needs to submit the name of the zone, not the default to_s value. To do that, try the following in the form:

ruby
= f.input :time_zone, collection: ActiveSupport::TimeZone.us_zones.map { |zone| [zone.name, zone.name] }, selected: @company.time_zone.nil? ? Time.zone : @company.time_zone

In the model I only validate against US time zones in the following fashion:

ruby
validates :time_zone,
    inclusion: { in: ActiveSupport::TimeZone.us_zones.map(&:name) }
Avatar

I found that setting ipn within paypal settings on the account webpage it works.

Under My Account -> Profile
Then listed below select
Selling preferences -> Instant Payment Notification preferences

Set your callback address here and they'll ping though correctly.

Avatar

Thanks a lot for the tutorial .. i am new to rails
can you please show me code of the partial used in the tutorial.

Avatar

After implementing that authorization solution, many of my controllers specs started failing because they are not authorized to run without the proper permission. How can I fake permission in a controller test to fix this problem?

Avatar

After implementing that authorization solution, many of my controllers specs started failing because they are not authorized to run without the proper permission. How can I fake permission in a controller test to fix this problem?

Avatar

Great screencast as always! I run into a problem though. Can't make it work to add fields. After click on "add" the browser jumps to the top and no field is added. Remove field is working.

Anyone had the same issue, and figured it out?

http://stackoverflow.com/questions/20136241/nested-model-forms-railscast-196-revised-adding-fields-via-jquery-not-worki

Thanks!

Avatar

I could be wrong, but remote links ( http://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html) are probably what you'd want to use to implement this now, right?

Avatar

I had the same issue however raising the timeout delay did not work for me. What I found though was the initial PJAX request was rendering the application layout, so I found this fix. In other words I added this:

ruby
def index
  # your code here
  render layout: false if request.headers['X-PJAX']
end

I haven't figured out why the initial PJAX request was rendering my application layout, which is weird especially given that when I make PJAX requests to all my other pages the same behaviour does not occur.

Hope that helps someone though. :)

Avatar

For anyone trying to implement this in Rails 4 don't forget to add {:category_ids => []} to params in the products_controller

ruby
def product_params
  params.require(:product).permit(
    :name,
    {:category_ids => []}
  )
end

And in that case you don't need a hidden field <%= hidden_field_tag "#{f.object_name}[category_ids][]", nil %>
nor params[:product][:category_ids] ||= []

Avatar

Does anyone have a comment about the recent states of MetricFu and SimpleCov?

Avatar

We created a gem at Continuum that provides a DSL on top of Roo for defining data importers. It's called active_importer and we think it could be useful for everyone. It's still a young project, and contributions are very much welcome.

Avatar

I feel very frustrated after 2 weeks posting question at stack overflow, contacting people from this comment section and trying to figure out by myself how to resize images on the client side using Ryan Bate's method, unfortunately I couldn't solve, my project is 2 weeks late, and I'm very disappointed for not having the best solution explained here... Tha'ts my feedback from this screencast.

Avatar

Ryan shows how to avoid a CSS collision in Episode #264 @ about 10:17 when discussing how the ActiveAdmin CSS can cause a conflict with the normal CSS.

Removing from the application.css file:

*= require_tree .

and manually loading each of them in works much better.

Avatar

Hi folks, what kind of naming convention do you propose for service objects?

I usually use nouns for class names. I used deverbal nouns for service names like 'ManagerInviter'. But in a review it was told to me to use verb as service names... like 'InviteManager'...

Which one do you propose and why?

Avatar

I second grammakov's request; plain javascript would be more helpful for me.

Avatar

How would I build tests for the "find_products" method?

Avatar

later versions of rails do not perform the search until you actually use the results. So every one of the calls in the code just builds a set of conditions.

it will not hit the database until you use "all" or "each" on "products"

Avatar

This makes me confusing for a long time. Thanks for your explanation.

Avatar

Hi here's the answer to my own question:

The latest versions of Papertrail actually namespace the Version class as PaperTrail::Version.

Problem solved.

Avatar

I had this working perfectly following this screencast and then some weeks later I went back to check on it and it was borked. Now I'm getting this error whenever I hit the undo button:

uninitialized constant VersionsController::Version

I have it set up exactly as in this screencast, but I have no clue what might have broken it.

Problem is on line 3 apparently:

class VersionsController < ApplicationController
  def revert
    @version = Version.find(params[:id])
    @version.reify.save!
    redirect_to :back, :notice => "Undid #{@version.event}"
  end
end

Any suggestions?

Avatar

How can i perform step validation in the latest version 1.0.2 with rails 4. As if: :on_categories_step? is not working.

Avatar

Hey guys -

Does anyone know if there's a way to get the Faye server (the one that Thin is used for) to actually log anything to console?

When I rackup the Faye server, I don't have the nice Rails-y output in the terminal - it just seems to hang (though it's definitely serving requests, just not saying anything about what it's doing in the background).

Here's what I mean:

http://cl.ly/image/0r2f3S1Y3P1P

It'd be nice if I could specify something in the faye.ru file (some config option) that told Faye to expose verbose server logs.

Avatar

Thanks David, this was annoying me!

Any idea why it just crashes the server like that? Seems pretty flimsy to me but what do I know.

Avatar

I had to change around_filter :scope_current_tenant to prepend_around_filter :scope_current_tenant to make sure the tenant was always loaded before my authorization before filter.

Avatar

This was exactly the answer I came here looking for. Thank you so much, hopefully it works for me.

Avatar

Can you be a bit more specific about where in the controller @user.avatar.reprocess! needs to go to fix the infinite loop problem? And will this fix work for Rails 4?

Avatar

I love every video Ryan does. Even those I don't understand, which is quite a few ; ) I'm a noob.

Quick question. For the sprites functionality portion of this video, do I really need that if the Asset Pipeline is working to concatenate my assets? I presume the sprite images will already be made one request. Sorry if I'm completely missing the point of sprites.

Avatar

Just a warning to anyone using page caching for more than HTML pages (e.g. JSON responses), the Rails will default to saving the cached file with the HTML extension, so requests hitting the cache will get the wrong format. To get around this, just append the format you're using in your request: curl railsapp.com/method.json. Rails will then save the file with the correct extension.

Avatar

The tutorial is great, helped me alot, but I have some problems with one thing.

In the tutorial in the first moment RB say to make a first express checkout payment and right soon create the subscription, but this is very bad, because the whole transaction happen in two parts, and I've been in troubles when the first payment happend smoothly, but the subscription is not created for some error.

Avoid this!
https://github.com/railscasts/289-paypal-recurring-billing/blob/master/saas-after/app/models/paypal_payment.rb#L15

Let the subscription make the first payment, case the subscription creation fails, the user won't make a first payment but no one subscription.

Avatar

Hey everyone, so I am trying to use this on Rails 4 with Devise, is this not supported?

I get this error:

activemodel-4.0.0/lib/active_model/deprecated_mass_assignment_security.rb:14:in attr_accessible': attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one. (RuntimeError)

Should I be using the "Protected Attributes" or having strong parameters defined in a controller somewhere, but which fields?

Thank you.

Avatar

Did you figure this out? It is quite easy. If I am understanding what you are asking correctly, a simple change in the routes.rb file should do it.

Avatar

I had the same question, isn't the object_id already unique? Thank you for writing your comment, I didn't even have to write out the code to find out for myself.

Avatar

Just did a little write-up which goes over how to add a repeating footer to your PDFs using Prawn - http://kyleke.es/posts/2013/11/creating-a-repeating-footer-w-prawn/

Avatar

The devise github readme has a good explanation of how to handle strong parameters with devise in Rails 4.

Avatar

If you are getting a 406 'unacceptable' when following the tutorial, then make this small change in your $resource in the coffeescript file:

"/entries/:id.json"

The .json makes it acceptable.

Avatar

Hi @FlintMakal - how about this for nested resources instead?

ruby
  def find_commentable
    params.reverse_each do |name, value|
      if name =~ /(.+)_id$/
        return $1.classify.constantize.find(value)
      end
    end
    nil
  end
Avatar

When trying to debug, in ImageWorker method 'perform' product.image.direct_fog_url(with_path: true) is equal to:
"https://testbucket.s3.amazonaws.com/uploads/2b33ecda-2d3e-4962-b365-e55d07bae205/$%7Bfilename%7D"

Avatar

I new in rails, i try to this work on rails 4, somebody had tried with this

Avatar

Using Rails 4.0.1 Carrierwave_direct solution. Images get uploaded to S3 but I'm geting an errors in the background processing:
"error_message"=>"Validation failed: Image could not download file: 403 Forbidden", "error_class"=>"ActiveRecord::RecordInvalid"

2013-11-14T16:56:09Z 3924 TID-owk35rblw WARN: Validation failed: Image could not download file: 403 Forbidden
2013-11-14T16:56:09Z 3924 TID-owk35rblw WARN: /Users/Andris/.rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.1/lib/active_record/validations.rb:57:in `save!'

Avatar

Hello all, Is there any demo application of implementing Riak database using Risky library in Rails application? I've googled alot but didn't find any. Even there is no episode in railscast for the same.

Avatar

Hello all, Is there any demo application of implementing Riak database using Risky library in Rails application? I've googled alot but didn't find any. Even there is no episode in railscast for the same.

Avatar

Agreed. For me, writing ng stuff on html template looks the same as writing Ruby code in erb. I'm okay with attributes and very simple logic such as "if" and iterator. But, no, thanks, no fancy stuff, no functions, I can't bare with them there.

Avatar

ericeche,
Did you ever get a solution?

Avatar

I get ERROR! THERE somebody can help me?
ExecJS::RuntimeError in Host_informations#index

Showing /Users/liucc/omm/app/views/layouts/application.html.erb where line #37 raised:

SyntaxError: unexpected TERMINATOR
(in /Users/liucc/omm/app/assets/javascripts/host_informations.js.coffee)

host_informations.js.coffee:
jQuery ->
Morris.Line
element: 'annual'
data: [
{y: '2012', a: 100}
{y: '2011', a: 75}
{y: '2010', a: 50}
{y: '2009', a: 75}
{y: '2008', a: 50}
{y: '2007', a: 75}
{y: '2006', a: 100}
]
xkey: 'y'
ykeys: ['a']
labels: ['Series a']

Avatar

If none of the solutions doesn't work. You can do a 'fix' by adding
'CREATE EXTENSION hstore'
in schema.rb file before any table is created and after running migrations.

After that you can call rake db:test:prepare and it will work.
Later you can just discard changes from schema.rb file.

Avatar

Same problem here, nothing gets populated. Have you figured it out?
thx!