Hi
I created nested models: tests-questions-answers
resources :tests do
resources :questions do
resources :answers
end
end
resources :questions
resources :answers
models:
class Test < ActiveRecord::Base
has_many :questions
accepts_nested_attributes_for :questions, :reject_if => :all_blank
class Question < ActiveRecord::Base
belongs_to :test
has_many :answers
accepts_nested_attributes_for :answers, :reject_if => :all_blank ,
:allow_destroy => true
to create new object for question i wrote in answers''s _form:
<%= render :partial => "questions/question",
:collection=>@test.questions %>
the view - questions/question:
<%= fields_for_question(question) do |q| %>
<div class="question">
<%= q.label :question %><br/>
<%= q.text_field :question %>
<div class="actions">
<%= q.submit %>
</div>
</div>
<%end%>
question controler:
def create
@test = Test.find(params[:test_id])
@question = @test.questions.create(params[:question])
But when i click on submit button. it does nothing!
can anyone help me please?
thanks
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Take a look at these railscasts: http://railscasts.com/episodes/196-nested-model-form-part-1 http://railscasts.com/episodes/197-nested-model-form-part-2 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you
But i have another problem:
How to use render(association.to_s.singularize , :f => builder)
when the partial is
in a diffrent folder ?
in the view there are 3 folders: ''tests'',
''questions'', ''answers''.
so in ''_form'' in folder-''question'' when
there is a call to-
link_to_add_fields("Add Answer", test_form, :answers)
i get the error-
missing partial ''tests/answer_fields''.
it need to be:
- ''answers/answer_fields''
what i need to change?
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.