Wicked gem shows only one step
I have watched Wicked forms with wizard and I am trying to do my own form,
I have the following:
Employees_controller.rb
class EmployeesController < ApplicationController
def index
@employees = Employee.all
end
def show
@employee = Employee.find(params[:id])
end
def new
@employee = Employee.new
end
def create
@employee = Employee.new(params[:employee])
if @employee.save
flash[:notice] = 'An employee has been created.'
redirect_to employee_admission_steps_path(:employee_id =>
@employee.id)
else
flash[:error] = 'An error occurred please try again!'
redirect_to '/dashboard'
end
end
def edit
end
def update
end
def destroy
end
end
Employee_admission_steps_controller.rb
class EmployeeAdmissionStepsController < ApplicationController
include Wicked::Wizard
steps :employee_admission1 , :employee_admission2
def show
@employee = Employee.find(params[:employee_id])
render_wizard
end
def update
@employee = Employee.find(params[:employee_id])
@employee.update_attributes(params[:employee])
render_wizard(@employee)
end
private
def finish_wizard_path
users_path
end
end
employee_admission1.html.erb and employee_admission2.html.erb
both files have the following line in the begining:
<%= simple_form_for @employee, url: wizard_path(employee_id:
@employee.id), method: :put do |f| %>
and the following line in the end:
<%= f.submit 'Next', :class => "btn btn-success" %>
<% end %>
routes.rb
resources :employees
scope 'employees/:employee_id' do
resources :employee_admission_steps
end
1- Now my main problem is after filling employee_admission1.html.erb and
press next , it goes to finish wizard. how to make it go to
employee_admission2.html.erb ?
2- the second problem i tried to add flash message into
def finish_wizard_path
users_path
end
but it didn't work.
3- the after_save in my employee.rb model is not working
def add_to_users
new_user = User.new
new_user.user_name = self.first_name
new_user.first_name = self.first_name
new_user.last_name = self.last_name
new_user.email = self.email
new_user.password = "123456"
new_user.password_confirmation = "123456"
new_user.user_type_id = 2
end
although I have the same method in student.rb and it works successfully
but student doesn't use wicked so i though it could the problem.
No comments:
Post a Comment