3

Where can I find a good Rails newbie-friendly reference about generating rails models with foreign key relationships?

I've found some pages indicating that you should add has_many and belongs_to to the relevant models to specify these relationships, but haven't seen any instructions for getting the scaffolds to generate the correct controller and view code that would reflect these relationships.

Jonathan Spooner
  • 7,682
  • 2
  • 34
  • 41
readonly
  • 343,444
  • 107
  • 203
  • 205
  • I realize that this comment comes way too late, but here's my post which refers to your post http://stackoverflow.com/questions/502119 – Dan Rosenstark Feb 02 '09 at 16:12

4 Answers4

3

http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

and check Chap 11 and 12 for Rails 3 and Rails 3.2 I hope you like those chaps and it is very nice concept for foreign key relationships

AMIC MING
  • 6,306
  • 6
  • 46
  • 62
0

It's not a tutorial as such but I find this page to be very useful when trying to figure out what my rails relationships should be. It's also an "official" guide so it's likely to be maintained.

http://guides.rubyonrails.org/association_basics.html

brimble2010
  • 17,796
  • 7
  • 28
  • 45
0

Look at question: Rails 3.1: Any tutorials for deeply nested models?

Also take a look at nested_form gem and relative documentation: http://rubydoc.info/gems/nested_form/0.1.1/frames. Usage is pretty simple.

Community
  • 1
  • 1
micred
  • 1,482
  • 1
  • 19
  • 19
-2

There are a bunch of StackOverflow questions asking for newbie reference materials. I recommend that you start with the two Peepcode screencasts:

They do a great job of visually introducing you to Rails 2 development. Then, I'd recommend you pick up the Rails 2.1 PDF by Ryan Daigle, to get the hang of the 2.1 features not covered in the screencasts.

I'm not sure what you're driving at with your question. What are you expecting the scaffolding to do? Create multi-object relationship links automatically? That's something you have to start layering in yourself....and as you do so, the scaffolding starts to be replaced with a real application. The scaffolding is just a starting point: it's not meant to guess what your inter-object relationships are going to look like in the application.

Pete
  • 1,517
  • 11
  • 19
  • (contributed by anonymous edit) NB: I was interested in this posting and expecting to find pointers to an example of step-by-step use of foreign keys, but the peepcode.com references are webcasts at $12 apiece, so many people may avoid them. Personally, I can find references on creating the foreign key relationships, but have yet to find a concise example of views and controllers to use them – Jeff Atwood Jan 26 '11 at 00:04
  • Downvote since you did not answer the question. This smells like an advertisment for your (non-free) screencasts. – Michael Ulm Oct 24 '11 at 18:31
  • Just happened to pop in and see this, quite sad. – Sturm Mar 14 '13 at 19:59