ruby on rails - NoMethodError in controller#new - undefined method -
i'm getting nomethoderror in new action of business_controller.
it seems acessing @business object form in view , error occurs then:
undefined method `businesses_path' here new method:
def new if business.where(:user_id => current_user.id).first.blank? @business = business.new else redirect_to user_businesses_path(current_user.id) end end my routes are:
resources :users resources :businesses member 'account' post 'payment' put 'update_password' 'membership' end end mind.blank's suggested changes
before_filter :check_if_user_has_business, :only => :index
def new @business = business.new end private def check_if_user_has_business redirect_to new_user_business_path(current_user) unless current_user.business end
do have route businesses_path or user_businesses_path? if have second 1 should specify url in form:
<%= form_for @business, url: user_businesses_path |f| %> also, if have correct associations set up, can write if statement follows:
if current_user.business.nil? # since it's has_one association here's how write it:
class businessescontroller < applicationcontroller before_filter :check_if_user_has_business, only: :new def new @business = business.new end private def check_if_user_has_business redirect_to user_businesses_path(current_user) if current_user.business end end
Comments
Post a Comment