Tuesday, March 20, 2012

[Rails] @model OR :model in a form_for

Hi Folks,

I want a form in a rails 3.0.10 app with form_for exactly I have 3
models

@apple, @basket, @table

class Apple
belongs_to :tables
belongs_to: baskets
end

class Basket
belongs_to :tables
has_many :apples
end

class Table
has_many :baskets
has_many :apples
end

MY QUESTION

For apples I have many color as well as for baskets I have many
different kinds of shapes

if I have the follow code in the index.html.erb file

<%= form_for :table do |f| %>

<%= f.collection_select(:basket, @basket, :id, :shape, {:prompt =>
true}) %>

<%= f.collection_select(:apple, @apple, :id, :color, {:prompt => true})
%>

<%= f.submit %>

<% end %>

*** appear the page correctly ***

meanwhile if I have the follow code

<%= form_for @table do |f| %>

<%= f.collection_select(:basket, @basket, :id, :shape, {:prompt =>
true}) %>

<%= f.collection_select(:apple, @apple, :id, :color, {:prompt => true})
%>

<%= f.submit %>

<% end %>

the page show the follow error page

////////////
undefined method `model_name' for NilClass:Class

Extracted source (around line #1):

1: <%= form_for @table do |f|
////////////

change only the first line in the example I have <%= form_for @table do
|f| %> and not

<%= form_for :table do |f| %>

NOW

which is the different between


<%= form_for @table do |f| %>

and

<%= form_for :table do |f| %>


sorry for this post but I want to understand the Rails philosophy

thanks a lot anyway,

C

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate