routing - Rails form_for multiple models no controller -


i'm new rails , trying create view form_for adds data in 2 different models. i've looked @ stack overflow posts multiple models, , i've used fields_for call submit information second model. however, form submission processes form_for data, , not fields_for. please advise on how fix this. 2 models users , schools (with goal of registering school , own information, being able log in , attach school adviser)

view code:

<div class="row">   <div class="col-md-6 col-md-offset-3">      <%= form_for(@user) |f| %>        <%= fields_for(@school, :url => {:controller => "advisers",                                        :action => "new_school"}) |s| %>         ... fields...       <% end %>       <legend>primary adviser information</legend>       ... forms ...       <%= f.hidden_field :access_level, :value => "adviser" %>       <p>&nbsp;</p>       <div class="col-md-12">         <%= f.submit "register", class: "btn btn-primary" %>       </div>     <% end %>   </div>   </div> </div> 

advisers controller:

def new     @user = user.new     @school = school.new   end    def new_school     @school = school.new(school_params)     @school.save   end 

routes:

 resources :advisers     collection       post :new_school     end   end 

output:

started post "/users" 24.13.7.99 @ 2015-07-16 19:41:37 +0000 processing userscontroller#create html   parameters: (params here)    (0.1ms)  begin transaction    (inserts user here)    (17.1ms)  commit transaction   user load (0.3ms)  select  "users".* "users" "users"."id" = ? limit 1  [["id", 6]] redirected https://pennmc2-mdmorant.c9.io/adviser 

notice activates user post not advisers post.

use accept_nested_attributes_for inside on of models - advisor/user?

  accepts_nested_attributes_for :school 

getting fields_for , accepts_nested_attributes_for work belongs_to relationship


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -