Я работаю над созданием контроллера для начинающих, который помогает новым пользователям загружать фотографии, находить друзей, приглашать людей и т. Д.
GettingStarted не имеет никакой модели, он просто ведет пользователей через мастера.Пользователь может полностью обойти этот начальный процесс, не нарушая сайт.Это всего лишь руководство ...
То, что я до сих пор делал, это:
- Создание маршрута, контроллера и модели:
Маршрут:
resources :getting_started
namespace :getting_started do
resource :users, :only => [:edit, :update]
end
Контроллер:
class GettingStartedController < ApplicationController
def index
@current_step = current_step
end
protected
def current_step
current_step || steps.first
return 1
end
def steps
%w[step1 step2 step3]
end
end
Модель
class GettingStarted < ActiveRecord::Base
attr_writer :current_step
attr_accessor :current_step
def current_step
#current_step || steps.first
return 1
end
def steps
%w[step1 step2 step3]
end
def next_step
self.current_step = steps[steps.index(current_step)+1]
end
def previous_step
self.current_step = steps[steps.index(current_step)-1]
end
def first_step?
current_step == steps.first
end
def last_step?
current_step == steps.last
end
end
View:
<%= @current_step.inspect %>
<% form_for @gettingstarted do |f| %>
<table>
<tbody>
<tr>
<td>
<%= link_to image_tag current_user.profile_pic.url(:large), :class => 'getting-started-profile-pic' %>
</td>
<td>
<a href="" class="getting-started-link">Upload a photo</a>
</td>
</tr>
<table>
<tbody>
<% end %>
Сейчас я застрял в вопросе о том, что мне нужен GettingStarted, чтобы вести пользователей по существующим моделям, а не быть самой моделью.И я получаю неопределенный метод `имя_модели 'для NilClass: класс
Предложения, мысли по поводу вышеизложенного?
Спасибо