RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Thanks as always for your amazing screen-casts. Is the full stack-trace not available in the testing log file? That is where I usually look for errors during testing...

Cheers

Avatar

Thanks Ryan! I'm a big fan of Railscasts.

I'm running into a snag. http://localhost:3000/companies.js is not rendering the html as expected and has <li> and <ul> take in it. When I look at the source with firebug, I see <pre> tags are included in the output. I'm new to this, and think there may be an easy fix or obvious oversight.

Any help is greatly appreciated!

Avatar

At the very least Ryan please disable comments for the older screencasts. New comments on those seem to be about 99% spam.

Avatar

Damn, looks like I'll have to rename my forthcoming "Ugg" Gem then! ;-)

Avatar

Thanks Ryan, nice screencast. Please post more TDD/BDD videos, I can't seem to get enough of those :)

Thanks again!

Avatar

Thanks for the feedback guys. I'm planning to deal with the spam problem soon. Captcha doesn't stop it because it's actual humans spamming AFAIK.

Avatar

Wonder why the captcha does not prevent that spam. I just replaced my old captcha (simple_captcha rails plugin) with the recaptcha used here, in the hope that it will work better...

Avatar

Ryan, you need to do something about the spam. I think you should disable all links that aren't to pastie, github, or the similar.

Avatar

suggestion if comment.include?('UGG')
 then move to spam

Avatar

Thanks Ryan

Keep up the good work.

Avatar

Ahh, to get the trace you would run the rake task with --trace, right?

I haven't tried this though..

Avatar

Thanks to this comment: 23. Beate Oct 31, 2007 at 02:34

I could look into my error. The link to Josh Owens' Website is not anymore working.

Here's the simplest solution. The code in the migration *will* work, but before you set ":counter_cache => true" in the model.

That said, I'd love to see the code in this page (and in pastie) updated with the "other solution".

Thanks for your good work Ryan. Cheers.

Avatar

What generated that nice list of exceptions? That one in file "untitled 1496" ?

Avatar

Thanks, definitely useful stuff.

Avatar

This is exactly what I was looking for :) great job

Avatar

Thanks for this. We're pushing a site into production soon, and this looks like it will help us cover a part of our tests.

Thanks again!

Avatar

thx for the cast!

Avatar

You are performing a wonderful service. I'm new to rails and web programming but have been building commercial applications for 30 years.

I tried to implement your anonymous scoped search in a seemingly simple search and end up getting:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.prospects

Extracted source (around line #3):

1: <h1>"Search" </h1>
2:
3: <%= render :partial => @Prospect.prospects %>

It appears the search is not being performed. What am I missing? Do you put any code into the 'show' def in the search controller?

If you do not have time to assist me perhaps you can suggest a consultant I can employ to help.

Thank you...keep up the good work!

John Lewis

Avatar

To connect to gmail, use the plugin
http://github.com/collectiveidea/action_mailer_optional_tls
It has been updated to support Ruby 1.8.6 and 1.8.7 both.

Avatar

To connect to gmail, use the plugin
http://github.com/collectiveidea/action_mailer_optional_tls
It has been updated to support Ruby 1.8.6 and 1.8.7 both.

Avatar

great stuff! so, what about dynamic select boxes?? still by hand?

Avatar

Hi,

Can you help me with this error :

uninitialized constant Formtastic::SemanticFormBuilder::I18n

Extracted source (around line #6):
3: <%= error_messages_for :task %>
4:
5: <% semantic_form_for(@task) do |f| %>
6: <%=f.inputs %>
7: <%=f.buttons %>
8: <% end %>
9:

Avatar

Any ideas how i get the code from the complex forms railscasts to work with formtastic ?

How would that project example look in formtastic ?

  <% for task in @project.tasks %>
    <% fields_for "project[task_attributes][]", task do |task_form| %>
      <p>
        Task: <%= task_form.text_field :name %>
      </p>
    <% end %>
  <% end %>

Avatar

Not bed, API is very interestinc for internet.

Avatar

@dani have you performed a ruby script/generate pickle? This will append pickle setup to features/support/env.rb and create a new file at features/step_definitions/pickle_steps.rb

Avatar

Thank you for its - much help in decision of my problems

Avatar

Ryan

Looks like you've had a herd of trained monkeys who've managed to post nearly 50 link spam comments to your site. Must be human to get through the Captcha.

Avatar

I noticed that I was getting the error nil.now when starting the rake jobs:work so I had to apply the patch from this link

http://github.com/kossnocorp/delayed_job/blob/master/lib/delayed/job.rb#L251

Avatar

Hopefully this will help someone out. I had a problem with this not rendering my javascript and just submitting through the format.html. turns out that because I was rendering the form with a button which popped it out, the DOM didnt pick it up in the beginning so I couldnt perform the JS on it. I tried $(#div).live but that doesn't support submit, so I ended up just embedding this code in the partial:

jQuery.ajaxSetup({
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

jQuery.fn.submitWithAjax = function() {
  this.submit(function() {
    $.post(this.action, $(this).serialize(), null, "script");
    return false;
  })
  return this;
};

$(document).ready(function() {
  $("#new_review").submitWithAjax();
})

Then it works fine!

Avatar

Pickle doesn't work form me!! I even download the episode source code and when i run "cucumber features", cucumber doesn't recognice the pickle steps!! Any suggestion?
 

Avatar

Is there any explanation as to why we need to use 'attr_accessible' on all attributes in the model? Seems like a lot of work...

Avatar

I'm pretty fed up with Factories, and specifically Factory Girl.

Yes, they can make for easier-to-read tests. But they're a lot slower than fixtures, and Factory Girl is so poorly documented that they waste huge amounts of my coding time. In some cases, it's also very inflexible, and things that would be easy to do with fixtures are very hard to do with Factory Girl.

Example: try finding the documentation for how to create a simple has_many relationship. Say, Topic has_many Posts, such that your default factory for Topic creates one with three simple posts.

Avatar

I've played with ActiveResource a bit recently, and found it lacking. I did, however, write up a little bit about it here on my blog; mostly dealing with hacks (or, as some might say, work-arounds) to deal with shallow nested routes.

Avatar

Thanks Ryan for great Casts!
They truly open RoR for many people.

Avatar

Is there any way to control the junk posts like above? Please do something... these guys are annoying.

By the way-Great episode and thank you for that.

Avatar

could this be used to create an upload status bar?

Avatar

I completely agree with you, reading some of the docs can be a pain in the butt. The links you posted have been very useful for me and I will use them in the future. Thanks a lot for posting and I hope you keep up the good work for this site and we can see more of you. Alternative sites to process API are not an easy thing to find :)

Avatar

In my case it works all fine.

And pls kill this spam :-)

Eric

Avatar

When using model associations (@user.posts), @post.categories, etc), you can order the options by using the :collection parameter:

<% semantic_form_for(@user) do |f| %>
  <% f.inputs do %>
    # Posts is an association to users
    <% f.posts, :collection => Post.all(:order => :name) %>
  <% end %>
<% end %>

Avatar

@Austin Ginder try to use will_paginate for it. I think it's the only way for now.

Avatar

Solved :D. I overwrite readonly? method in controller so:

def readonly?
     false
end

Avatar

Hi, thanks for great tutorials ! I tried build complex form for habtm associtions, but I get this error: ActiveRecord::ReadOnlyRecord. Please can you help me and describe me how it works and how to fix it? Many thanks.

Avatar

As usual, Great cast!!
I tried to convert the table into lists as follows in the view:

<ul id="products">
<% @products.each do |product| -%>
  <li><%= h(product.name) %></li>
  <li><%= number_to_currency product.price %></li>
<% end -%>
</ul>

with step definition:

Then(/^I should see products table$/) do |expected_table|
  html_table = element_at("#products").to_table
  #html_table.map! { |r| r.map! { |c| c.gsub(/<.+?>/, '') } }
  expected_table.diff!(html_table)
end

But I could not figure out the error. Whats wrong with my setp def?? plz.

Avatar

Great Ryan.. Amazing..........

Avatar

great tutorial. thanks a lot mate.
took me a week to make this work but still a great code

Avatar

@stu Pickle doesn't have anything built to handle the deletion of records but it isn't hard to create your own step definition using Pickle to achieve this: http://gist.github.com/224945

Avatar

A note to those using Autotest: you might want to add an exception to ignore your '.git' folder

Avatar

Better Git support is built into msysGit:

Avatar

Yes, sorry. I meant that that "git add ." is only needed the first time for new files and the following times (for existing files) should "git commit -a" be enough...