I have a has_one association in my model with my user. What Im trying to do here is simple but Im having a hard time understanding whats wrong here. So since I have a has_one association with my model, in my mind I was simply thinking that if the user has already created the model associated with the has_one association if he tries accessing "localhost3000/model/new" I would redirect him to the edit page of this particular model. Here is what I have but its telling me its not working as intended. Its as if my if statement is not catching anything
class BusinessesController < ApplicationController
before_action :set_business, only: [:show, :edit, :update, :destroy]
def index
@businesses = Business.all
@buzzs = Buzz.all
end
def show
end
def new
if current_user.business.nil?
@business = current_user.build_business
else
render 'edit'
end
end
def edit
end
def create
@business = current_user.build_business(business_params)
if @business.save
redirect_to @business, notice: 'Business was successfully created.'
else
render "new"
end
end
This error doesent make a lot of sense to me because it says its an error in the "new" controller which would have rendered it to the edit path thus not being nil
Aucun commentaire:
Enregistrer un commentaire