RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Exactly what I needed, exactly when I needed it. Thanks, Ryan. Looking forward to Part Deux.

Avatar

Interesting. I was unable to get this functionality working in formtastic.

I'll try again, mimicing Ryan's code.

Thanks!

Avatar

Yes, formtastic supports nested models.

It's in the documentation.

http://github.com/justinfrench/formtastic

Avatar

Does anyone know if formtastic supports nested models?

Avatar

I have the same issue as klumsyBird and gordon. I've spent hours trying to figure it out but just can't get it to work. I'm on Linux Centos 5.x. Installed it on Leapord OSX and it works perfect, but not on my linux server :(

Avatar

This is a great update to one of my most-referenced railscasts! So glad to see the multiple nesting and how much easier it has become in Rails 2.3!

Avatar

Something wrong with cancan? Your "Report as Spam" links don't work anymore and opening them in a new window gives me a "Not authorized to access this page." message.

If I may suggest a cast topic: could you do a cast on testing models with associations and sessions? I find this really troublesome. My app works, but a lot of tests fail, because some objects turn out to be nil. I have nailed this down to sessions not working so well. I have found a snippet of yours in some forum, but this doesn't help. Well, it did help, but sometimes it doesn't. Very strange...

Last, but not least: Thanks for all those great screencasts. :-)

Avatar

@nico:

Of what I saw when using that plugin it never supported auto-indentation. Kinda pain in the ass to always press tab 5 times just to get to the right line.

Avatar

First off, great screencasts. Love them all and look forward to new ones every week.

Avatar

he use of the instance variable comes down to intelligent choice, really. It seems unlikely that you're going to calculate the total weight

Avatar

The first known use of the term "refactoring" in the published literature was in a September, 1990 article by

Avatar

Would it be possible in a future show to also give an example of how to ask questions that are dependent on the answer. Like: if answer == 2
then ask these 4 questions, etc.?

Thanks.
Great Screencasts!!!!

-Luis.

Avatar

Excellent railscast Ryan.

If I has several tasks, say 50 or more, I don't want to add a single text field but search for a particular task. Any ideas in which direction I should go?

Many thanks,
John

Avatar

It's amazing how often these screencasts come out just as I'm trying to figure out how something works.

Specifically, the reject_if was something I was wondering how to implement for today. Thanks for saving me a few hours! :-)

Avatar

Superb. You have raised the screencast quality bar to a new level.
I really love how your increasing mastery of the art is expressed by the emergence of a subtle humor: the finger snap, the answer to the universe... I follow your casts to learn, obviously, but beyond pure information I find them enjoyable because of the sense of being spoken to directly. I'm so impressed.

Avatar

Great stuff Ryan!
Try looking into LowPro for Prototype to create a nested behavior JS class (andd/remove links). It makes your JS code very reusable (http://bit.ly/76dDzz) and there is a version of LowPro for jQuery. And if anyone cares, RightJS comes with most of the functionality built in ;)

Avatar

Hello Ryan,

Thank you for yet another awesome cast!

BTW, how are you filling the forms with a touch/click? Which plugin/tool are you using for that?

Thank you!

Paddy

Avatar

Awesome timing. I just had to do this in a project and wasn't 100% sure I was doing it properly. This just confirmed it for me!

Thanks!

Avatar

Thanks Ryan! Can't wait Part 2 ;) BTW what is the TextMate plugin you use for creating partials? I can't find one working. Same thing with the one putting links to TextMate when an error occurs, couldn't make it work (this is a Rails plugin, not a TM).

Avatar

As always, excellent Ryan. I've been a heavy user of the complex forms method, this looks way smarter.

Avatar

Does accepts_nested_attributes_for work well with virtual attributes?

Avatar

Hi,
Im creating my first Rails project and Im having a problem with
Authlogic. I need to have a User with specified name, surname, etc.
(and of course essential Authlogic fields). Is it possible to create
one migration with mentioned additional fields and those from
Authlogic?

Thanks.

Avatar

using latest nifty_generators, in the survey model i see the following, but it's not in the railscast:

attr_accessible :name

unless i comment this out, cannot edit questions/answers

Avatar

Lovely.

Can't wait to see some Rails 3 specific stuff :)

Avatar

Nested model forms are really helpful, I use them right now to add some generic attributes to different models with a has_one relationship. I am wonder how to add these javascript add / remove links though, it seemed not so easy last time I searched for a solution.

Avatar

Thanks for this Ryan, looking forward to this series.

As it happens I am near completion of a survey website in which I am making use of nested model forms.

I came across a painful bug in the version of rails which I am using (2.3.4):
Check boxes used for data entry (e.g. a boolean value in my model) cause the hashes in params to be split for nested models when the user ticks them.

For example I have a form which includes a nested model called "CourseOffering".
When the user does not tick any check boxes the params hash includes a course_offerings_attributes hash which itself contains one hash for each course offering (as you would expect).
When they do tick a check box, that particular course offering gets split into two different hashes, this causes various problems depending on validation rules.

The only way I was able to overcome this problems was to use select boxes instead.

I hope I have explained this clearly enough - I think it's something to watch out for!

Avatar

I've heard this can work somewhat for has many through, but I've not seen a concrete example. Is that what part 2 might be?

Avatar

I'd like to add http://www.MyTaskHelper.com
to this great list. Great free online database application. Very useful if you need simple form but don't want to develop it in Rails, but instead you can make in a few clicks.

Avatar

Thanks Ryan. Very goog job!
Can I suggest another screencast related to this one?
I really appreciate something like this with MongoMapper?
The surveys sample fits very well with the concept of a document database.
Is it possible?
Thank you very much.

Avatar

@Fredrik:

There is a netbeans haml plugin: http://mediacast.sun.com/users/tnorbye/media/org-netbeans-modules-haml.nbm/details

Avatar

however I realized that if I had a

Avatar

I am working through this episode, however I realized that if I had a

Avatar

Is there any way to deal with captchas with mechanize? Seems like more and more pages particularly any type of form submission have captcha.

Avatar

Thanks for this tutorial. I've been looking for some time for a decent one on dynamic select menus. You'd be surprised how much trash info there is out there.<a href="http://oynetwork.com/">lead</a>

Avatar

has anyone been able to get workling starling work on windows?
i could finally install starling on windows and get the process to start. but workling_client fails to start.

is there a workaround or is it a lost cause?

thanks

Avatar

Nice history tip, Ryan.

I created a method in my .irbrc that easily allows me to get the history of this or previous sessions as well as being able to limit to a certain number of lines ala

hits :all, 25

You can get the code at http://gist.github.com/272588

Avatar

Just wanted to say: thanks for all the superb tutorials! Keep up the good work!

Avatar

I'm a newbie to rails and adding this post to clarify the railscast. I was wondering why the def was called "self.find_incomplete" when the original code was "find_all_by_complete". It took me a few minutes, but it's called "incomplete" because the data being queried is a boolean condition and the query is looking for the "false" conditions (i.e. tasks that are not completed) ergo the naming if "incomplete". Yes, a Homer Simpson DOH! moment...

Avatar

I'd add http://guides.rubyonrails.org and http://heroku.com :)

Avatar

There is a good and simple tutorial for isntalling mongodb, you wont need to compaile it
http://www.slideshare.net/scottmotte/mongodb-1825613

Avatar

@roberth: I had to add a user.roles_mask_will_change! to my migration code, to make changes hit the db. It was working correctly in the console. Not sure what the issue is. I'm running Rails 2.3.5.

Avatar

@jamesw

Seems like Netbeans lack support for HAML though. I've searched around for plugins to get it working, but no success.

Seems like right now the only editor working (at least for me) is RadRails on Windows.

Gosh sometimes I just hate that I aint on textmate/OSX.

Avatar

i m also facing the same problem with "riddle" as per klumsyBird.
 Can anyone please shine some light into this?

Avatar

Netbeans for for code development is awesome.
http://netbeans.org/

RailsPlayground for hosting
http://railsplayground.com/
Totally brilliantly helpfull. There is no way I would have got my app running the way I wanted without their help.

As a RailsPlayground customer I got a free sourcerepo account with redmine for secure source code repository and project managemant.
http://sourcerepo.com/
Having used this set up in anger I would happily pay for the service.

Last but not least http://railsforum.com/index.php as a superb place to ask for help

Avatar

Hi,

I am trying to run a curl url from my terminal and I am getting permission denied error.

curl -H "Accept: application/xml" http://localhost:3000/readings?current_user=1

I tried this as well:

curl -H "Accept: application/xml" http://localhost:3000/readings?user_id=1

in my readings controller I have before_filter method set.

Kindly suggest me how would I fix that.

Thanks
Puneet

Avatar

use ruby script/plugin install http://github.com/mislav/will_paginate.git

Avatar

OK, it was of course my problem. The in-episode fast forward (at the bottom inside the frame) still does not work, but the iTunes scrubber (top, green window) does as always. Strange, but nevermind.

Avatar

Hello all, and thanks Ryan for your great work with these episodes. I've managed to make that work, but slightly modified to work with jQuery.

There's a little trap when using virtual attributes in a way like this

  def document_name=(name)
    self.document = Document.find_by_name(name)
  end

In face, Model.find_or_create_by_name() is handy, but when you pass no name, no Model is being created by ActiveRecord. Though, self.document = XX is still being affected, and a Document object is thought to be present in the parent model. But, in this case, XX is empty (no Document found, and no Document saved to the database yet), thus XX.id is not present, and that leads to strange behaviors as the XX Document is not a "classic Document". Calling document_path(parent_model.document) immediately after the parent_model update or save, causes crashes. Immediately after means, in the partial I'm trying to generate for the response to the browser, in my AJAX context.

I hope my explanation was not too messy to be understood.

Avatar

Great Railscast as usual! Digging a bit further, i found using named scopes essential...