'active_record-acts_as nested form
I have integrated active_record-acts_as gem for role based attributes management. I have user as the parent model and doctor, student as the acts_as model as below,
class User < ActiveRecord::Base
actable
end
class Doctor < ActiveRecord::Base
acts_as :user
end
class Student < ActiveRecord::Base
acts_as :user
end
some common fields like first_name, last_name, contact_no belongs to user and uncommon fields goes to other respective models. I have integrated step form using wicked gem. Now when user signs up he is redirected to the second step where I want to update few fields from user and few fields from doctor model.
How can I use nested form ??
my form object belongs to doctor model
<h3> Let us know more about yourself </h3>
<%= render layout: 'form' do |f| %>
<div class="field">
<%= f.label :existing_email %><br />
<%= f.text_field :existing_email %>
</div>
<%= f.fields_for f.object.acting_as do |ff| %>
<div class="field">
<%= f.label :mobile_no %><br />
<%= ff.text_field :mobile_no %>
</div>
<div class="field">
<%= f.label :country_id %><br />
<%= ff.text_field :country_id %>
</div>
<% end %>
<% end %>
controller for wicked#steps management
class RegistrationStepsController < ApplicationController
include Wicked::Wizard
steps :step_two
def show
@user = current_user.specific #docotr object
render_wizard
end
def update
@user = current_user
@user.specific.attributes = doctor_params
render_wizard @user
end
private
def doctor_params
params.require(:doctor).permit!
end
def redirect_to_finish_wizard
redirect_to root_url, notice: "Thank you for signing up."
end
end
getting error as,
User(#154180) expected, got {"mobile_no"=>"+919702610970", "country_id"=>"India"} which is an instance of ActiveSupport::HashWithIndifferentAccess(#54060)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
