Has one association with nested form not working rails 5


#1

i have implemented has one nested form in rails 4.2.7 but same is not working in rails 5

this the the server log

Started POST “/drivers” for 127.0.0.1 at 2016-08-24 22:24:44 +0530
Processing by DriversController#create as HTML
Parameters: {“utf8”=>“✓”, “authenticity_token”=>“vFh5v5tzJMYtGtZLHSnSv61KI3zsUMu9tGLF0KI7sH6O3idS2Xzn2WkKgtdVxJCcZuXG4QZNZZIjkT7vGYDTOw==”, “driver”=>{“name”=>“adfa”, “license_attributes”=>{“number”=>“df”}}, “commit”=>“Create Driver”}
(1.7ms) begin transaction
(0.1ms) rollback transaction
Rendering drivers/new.html.erb within layouts/application
Rendered drivers/new.html.erb within layouts/application (6.6ms)
Completed 200 OK in 49ms (Views: 34.1ms | ActiveRecord: 1.8ms)

my controller is

class DriversController < ApplicationController

def index
@drivers = Driver.all
end
def new
@driver = Driver.new
@driver.build_license
end

def create
@driver = Driver.new(formparams)
if @driver.save
redirect_to drivers_url
else
render ‘new’
end
end

private
def formparams
params.require(:driver).permit(:name, license_attributes: [:number])
end
end

my model is
class Driver < ApplicationRecord
has_one :license
accepts_nested_attributes_for :license
end

is there is way to implement this in rails 5


#2

Please use the preformatted text option when pasting in code. it makes it much easier to read. Just select all your code and press the the </> button to format.

It will make your code look like this:

class Foo

  def bar
    puts "some code"
  end

end

When your code is easier to read, you are more likely to get a response.