I am creating an application in rails in which a freelance has a has_one association with a service. the app is running well until you have to create a new service as a freelancer. when I create a new post I get the error.
I did a test leaving the freelancer association with has_many and it works perfect leaving current_freelancer.services.build. but with has_one I get the error mentioned above.
NoMethodError in ServicesController # new undefined method 'services' for # Did you mean? service service =
the controller for the services is as follows.
class ServicesController < ApplicationController
before_action :set_service, only: [:show, :edit, :update, :destroy]
def index
@services = Service.all
end
def show
end
def new
@service = current_freelance.services.build
end
def edit
end
def create
@service = current_freelance.services.build(service_params)
respond_to do |format|
if @service.save
format.html { redirect_to @service, notice: 'Service was successfully created.' }
format.json { render :show, status: :created, location: @service }
else
format.html { render :new }
format.json { render json: @service.errors, status: :unprocessable_entity }
end
end
end
end