Try to build a welcome wizard and try to get existing rails code to be ported to be rails 4 compatible. Based mostly on previous great answer: https://stackoverflow.com/a/17255451/355281
I try to call http://books:3000/welcome/basics
This results in:
Circular dependency detected while autoloading constant WelcomeController
app/controllers/welcome_controller.rb
class Welcome::ApplicationController < ::ApplicationController
layout "welcome"
before_filter :authentice_user!
end
app/controllers/welcome_basics_controller.rb
class Welcome::BasicsControlller < Welcome::ApplicationController
before_action :authenticate_user!
before_filter :allowed?
def new
@step = Welcome::Basics.new(current_user)
end
def create
@step = Welcome::Basics.new(current_user)
if @step.save(params[:welcome_basics])
redirect_to welcome_some_other_step_path, :notice => "Yay"
else
render :new
end
end
private
def step
@step ||= Welcome::Basics.new(current_user)
end
helper_method :step
def allowed?
redirect_to previous_step_path unless step.allowed?
end
end
**app/models/welcome_basics.rb
class Welcome::Basics
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def persisted?
false
end
def initialize(user)
@user = user
end
attr_reader :user
delegate :some_field, :some_other_field, :to => :user
validates_presence_of :some_field
def save(params)
user.some_field = params[:some_field]
user.some_other_field = params[:some_other_field]
if valid?
user.step = 2
user.save
end
end
def photo
@photo ||= Photo.new
end
def profile
@profile ||= user.profiles.first
end
end
/config/routes.rb
namespace :welcome do
resource :basics, :only => [:new, :create]
end