RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Can partials be cached with this approach?

Avatar

Wow .. Better Errors is excellent ... Love it

Avatar

I also had to use Unicorn to get the pdf to load.

However, PDFKit leaves me with this dilema:

Option 1:
Enable CSS to show up on page. Unfortunately, no text / content will show up!

Option 2:
Do not have any CSS on the page. Now the text / content shows up!

Oh joy. Hoping Prawn will leave me with more desirable options...

Avatar

Is there any way to only call activities which have an owner in the controller as opposed to the view?

Avatar

I've followed this tutorial just like it is but it gave me this:

SMTP error: 530 5.5.1 Authentication Required.

i've google it everywhere and finally i could! using the SMTP configuration like this:

ruby
puts "config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'catec.edu.bo',
  :user_name            => '<USER>@gmail.com',
  :password             => '<PASSWORD>',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }"

I hope it helps,
Best Regards!

Avatar

Same problem here. Submitted it as an issue on the gem - https://github.com/rubber/rubber/issues/319.

@carlosmendes @skwasha @Heber Massami Nunomura @rich833 @kmamit Did you get it to work and how?

Edit

If I do cap deploy afterwards, then it deploys and works fine, but this issue should probably be fixed

Avatar

I have used https://github.com/dbrady/tourbus for simulating multiple concurrent users. you will need to use jruby to run the test client.

Avatar

Good episode - thanks.
juts wondering if anyone knows of a way to load / stress test a rails app simulating multiple users logging in at the same time

Avatar

Cheers Ryan, much appreciated.

One thing tho (that doesn't really matter!)...

entires_controller.js.coffee should be entries_controller.js.coffee surely?

+1 on Rachid comments - one of the things I love about railscasts is how succinct they are.

Avatar

There's a problem with the escaping in firefox 10. Apparently it will escape the escaped_country variable again:

escaped_country === "United\\ States"
true

escaped_country === "United\ States"
false

And it will break the filter...

Any idea what browser we actually need to escape first? I've tested with IE8 and chrome and they also both work with \' in the country name without escaping.

Avatar

There is this Gist I have found: https://gist.github.com/galaxylord/1451289

It basically boils down to this:

ruby
      it 'takes time' do
        Benchmark.realtime{
          get :index
        }.should < 1.5
      end

It would be awesome to see some native support for RSpec, if it is appropriate, but the real question is why there is no API yet in RSpec, being such a popular project.

Avatar

All my request seem to get canceled after 650 ms.

javascript
$('a').pjax
    timeout: 10000

the console starts and then the status is cancelled? seems the timeout isn't working, as I read the default timeout is 650ms. any ideas?

Avatar

Thanks Ryan - awesome as usual and well worth the wait!

It's probably worth mentioning that the reason number_to_currency is popping up is because the example page isn't doing much, so the time spent in the call becomes significant.

Avatar

FYI, I think rake test:benchmark is currently broken with rails 4 beta.

Avatar

I am using cancan for assigning roles to user.

I have category and subcategory table and another table shop.
Each shop have many categories and categories have many subcategories.
The user belongs to one shop and how can i say in ability the user of this shop can edit the subcategories that belongs to the category of that shop.

Avatar

Is there a way to use this with RSpec?

Avatar

I'm curious: How can the tasks be configured to be more lightweight? (i.e. not loading the entire rails environment)

Avatar

Can you post your code? Are you using HABTM or HMT? Have you created a join table? You will definitely need attr_accessible :skill_ids for Rails 2/3, or params.require(:model).permit(:skill_ids) in the controller if you're using Rails 4. I'm happy to help if you can share your code. Maybe add it to a gist and then reference it in a reply.

Avatar

Thank you very much. This saved me a lot of time.

Avatar

Does anyone know if there is a way to get multiple file uploads and the progress bars to work in IE?

Avatar

In the end I dropped the jQuery file upload gem soloution all together & followed Episode #196 for uploading multiple images.

Avatar

I'm combining this with dynamic forms from episode #403. The jQuery doesn't fire for the properties when looping through the following lines...

edit.html.erb
<%= f.fields_for :properties do |builder| %>
  <% @product.product_type.fields.each do |field| %>
    <%= render "products/fields/#{field.field_type}", field: field, f: builder %>
  <% end %>
<% end %>

The datepicker works perfectly for anything being edited that isn't within properties. Troubleshooting it seems that the issue is jQuery being called/attached/whatever-term-you-want before the builder finishes. If I add the following lines, the name will trigger its changes, but the date will not.

products.js.coffee
# For the sake of testing, I've hard-wired the id names in to eliminate passing the id names as being the problem.
jQuery ->
$("#hardware_model_name").change ->
alert "name has been changed"

jQuery ->
 $("#hardware_model_properties_test_date").change ->
   alert "date has been changed"

How does one properly include the jQuery for render calls?

Avatar

The table builder date selection is not recognized by Rails (3.2.11). After selecting the date and creating the new object, the date fails my 'presence: true' validation. I get an error message "Date can't be blank'.

Has anyone seem this type of error?

(Note: I am using watu table builder)

Avatar

Have you restarted your server? that was my problem

Avatar

One more quick discovery/question. With the second method, I was getting spurious locking errors added to base on creation. It turned out acts_as_list and other such plugins intercept the create process and perform some quick saves to get things in the right place. Not sure I completely understand, but I needed to pass the validation if nothing was in the changes array:

ruby
# app/models/item.rb
def handle_conflict
    if @conflict || updated_at.to_f > original_updated_at.to_f
      
      # Commented out because of ability to submit again and overwrite previous value
      # @original_updated_at = nil    
      
      # acts_as_list and other items update the position and cause spurious conflicts during creation
      if changes.empty?
        @conflict = false
      else
        @conflict = true
        errors.add :base, "Snap! Someone signed up for this just a moment ago. Pick something else?"
        changes.each do |attribute, values|
          errors.add attribute, "has just been reserved. Cancel to reload sheet."
        end
      end
    end
  end

This got my simple creation action up and running again. Thanks for this great episode and any insights on whether this is a short sighted fix. Charles

Avatar

From my point of view the EmberJs is really powerfully, but apply the EmberJs inside partially client side site is super hard (for me)!

I found really nice alternative the Serenade.js. On home page examples of code with is really easy to understand. I feel that I have control over code, I can understand how it work.

Hope it will help :-)

Avatar

Thanks so much as always! There is an episode for nearly every thing I want to do! Amazing!

Using the second method, I had a behavior with a remote form that I wanted to pass by the group. I got the first validation error just fine. If I hit submit again, however, the old value would pass the validation the second time and overwrite the value that was protected the first time around.

In other words, the conflict was not detected because @original_updated_at was set to nil and the object reloaded the new timestamp and passed the update right through. If I comment out the @original_updated_at = nil line, I get the behavior I want -- a durable block on any updates to that record.

Does this make sense? What was the value of setting @original_updated_at to nil in the code? Thanks for any advice you might have! Charles

Avatar

Why not use Postgres' full-text search @@ operator rather than LIKE?

Avatar

help,i have a trouble with the pjax ..

btw,my english is pool,maybe there's some mistakes ~

ok,i download the lastest pjax at https://github.com/defunkt/jquery-pjax
then code as the demo,but it doesn't work,also there's no errors.

head
<script type="text/javascript" src="jquery.1.9.js"></script>
<script type="text/javascript" src="../js/jquery/plugin/jquery.pjax.js"></script>

$(function() {
        $('#pjax-container').pjax('a',{timeout:3000});
});
body
<h1>My Site</h1>
<div class="container" id="pjax-container">Go to
        <a href="MyHtml.html">next page</a>.
</div>

when i click on the link,it refresh whole page.
could any one help me ?thanks a lot!

email:miles.luffy@gmail.com

Avatar

Years later, this is still very helpful, Thanks!

Avatar

You are totally correct, it really does what you said, which is the best solution. But I too share your problem: TextPost and Picture have comments (which I'd like to eagerly load), and SpreadSheet has collaborators, which I'd also like to eagerly load.

Avatar

I am also getting the "An unexpected error has occurred. We have been notified of the problem.". Has anyone found a solution???

Avatar

Did anyone track down this problem? I'm still trying to find a solution.

Avatar

I had the same problem, then I installed the following gems and it worked fine! (Rails 3.2.8)
gem "therubyracer"
gem "less-rails"

Avatar

I get the following error after running "cap rubber:create_staging

/Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/expects.rb:10:in response_call': Unable to find group 'blog_production_default' (Fog::Compute::AWS::NotFound)
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:332:in
response'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:226:in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/idempotent.rb:12:in
error_call'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/base.rb:10:in error_call'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:239:in
rescue in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:200:in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/idempotent.rb:12:in
error_call'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/base.rb:10:in error_call'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:239:in
rescue in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:200:in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/idempotent.rb:12:in
error_call'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/middlewares/base.rb:10:in error_call'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:239:in
rescue in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/excon-0.20.1/lib/excon/connection.rb:200:in request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/fog-1.10.0/lib/fog/core/connection.rb:21:in
request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/fog-1.10.0/lib/fog/aws/compute.rb:384:in _request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/fog-1.10.0/lib/fog/aws/compute.rb:379:in
request'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/fog-1.10.0/lib/fog/aws/requests/compute/authorize_security_group_ingress.rb:54:in authorize_security_group_ingress'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/fog-1.10.0/lib/fog/aws/models/compute/security_group.rb:104:in
authorize_port_range'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/cloud/fog.rb:182:in add_security_group_rule'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/thread_safe_proxy.rb:13:in
method_missing'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/security_groups.rb:218:in block (2 levels) in sync_security_groups'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/security_groups.rb:214:in
each'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/security_groups.rb:214:in block in sync_security_groups'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/security_groups.rb:208:in
each'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/security_groups.rb:208:in sync_security_groups'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/security_groups.rb:51:in
setup_security_groups'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/instances.rb:268:in block in create_instance'
from <internal:prelude>:10:in
synchronize'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/instances.rb:267:in create_instance'
from /Users/anderskitson/.rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rubber-2.2.4/lib/rubber/recipes/rubber/instances.rb:230:in
block (2 levels) in create_instances'

Avatar

I followed along but am getting this error

Can't mass-assign protected attributes: skill_ids

For whatever reason it doesn't understand the _ids (with the extra 's'). I tried to add :skill_ids in the attr_accessible area but it just gives me another issues:

unknown attribute: skill_ids

HELP!

Avatar

Hi Ryan,

Thank you very much for covering some Ember.js casts, it was enough for me to get me to start using it. Like giving me the right keys to open the doors I need.

I didn't miss tests like others suggested, my opinion is that it keeps you up in speed with covering several subjects in a short time.

To all the guys with suggestions to make the casts more sophisticated, packed with tests or other app types, don't need another peepcode.com site. I like the weekly and relatively short casts.

Keep up the good work Ryan, keep it simple!

Avatar

+1

I was confused by the following error:

ruby
    NoMethodError:
           undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa49a73c>

Since Capybara 2.0 one has to use folder spec/features Capybara commands don't work in folder spec/requests anymore.

Which I learned by your link. - Thanks!

Avatar

As someone named Jake, you sure caught my attention at 1:27.

Avatar

By using includes there, the polymorphic association is loaded in the best possible way (meaning that first it runs a query to load the feed items, and then, judging by the id/types it does a query for each type, and not for each instance, which from my point of view it's the best possible way to do it)

I had a more difficult problem posted here where I wanted to do an includes on the polymorphic model to eager-load other associated models, but ended up doing a manual sweep

Avatar

I agree. They are they a good reminder for optimization techniques and what has been deprecated as we move move into new Rails versions.

Avatar

You need to substitute this line

javascript
data.context = $(tmpl("template-upload", file))`

with this other line in the initialize method of the paintings.js.cofee file

javascript
data.context = $($.parseHTML(tmpl("template-upload", file))[1])