ruby on rails - Rendering nested form partials in other controllers -


i have 3 resources: jobs, questions , answers. relationships are: job has many questions; question has many answers; job has many answers.

i have nested of forms on jobs/new view.

now goal of app admins (us) create jobs , questions behind admin wall. once we want list out questions created each specific job , have users answer questions. requires putting answers form on view (same or different controller) not behind admin wall.

since forms nested on jobs/new view, created partial answers form:

 <%= form_for(@job) |f| %>  <%= f.label :name %><br />  <%= f.text_field :name %>   <%= f.fields_for :questions |builder| %>    <%= render 'question_fields', :f => builder %>   <% end %>  <%= f.submit %> <% end %> 

with question partial being:

<%= f.label :question, "question" %>  <%= f.text_area :question, :rows => 10 %>  <%= f.check_box :_destroy %>  <%= f.label :_destroy, "remove question" %>    <%= f.fields_for :answers |builder| %>    <%= render 'partials/answer_fields', :f => builder %>   <% end %> 

and answers partial being:

 <%= f.label "answer" %>  <%= f.text_area :answer, :rows => 10 %>  <%= f.hidden_field :question_id, :value => @question %>  <%= f.hidden_field :job_id, :value => @job.id %> 

my thinking create partial , able reference wherever want in app, have been trying , can't seem work.

i have 2 questions out of setup:

1) how go rendering answers partial on view (what correct code)? 2) best place create view? initial thinking jobs view since nested under parent resource, i'm not entirely sure if works.

thanks , let me know if need more info or clarification.

try following

   <%= render :partial=> '/partials/answer_fields', :f => builder %> 

instead of

   <%= render 'partials/answer_fields', :f => builder %> 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -