Ruby on rails Rails-创建GettingStarted控制器
我正在努力创建一个入门控制器,通过上传照片、寻找朋友、邀请他人等来引导新用户 GettingStarted本身没有模型,它只是通过向导引导用户。用户可以完全绕过此gettingstarted过程而不破坏站点。这只是一个指南 到目前为止,我所做的是:Ruby on rails Rails-创建GettingStarted控制器,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我正在努力创建一个入门控制器,通过上传照片、寻找朋友、邀请他人等来引导新用户 GettingStarted本身没有模型,它只是通过向导引导用户。用户可以完全绕过此gettingstarted过程而不破坏站点。这只是一个指南 到目前为止,我所做的是: 创建路线、控制器和模型: 路线: resources :getting_started namespace :getting_started do resource :users, :only => [:edit, :upd
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
<%= @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 %>
控制器:
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
<%= @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 %>
class GettingStartedController
型号
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
类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
<%= @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 %>
'入门配置文件图片'%>
现在我被困在一个问题上,我需要开始引导用户通过现有的模型,而不是模型本身。我得到了NilClass:Class的未定义的方法'model_name'
对上述问题的建议和想法
谢谢您的
GettingStarted
模型不必继承自ActiveRecord::Base
,但是它确实继承了,您得到了错误,因为Base在您的数据库中需要一个名为GettingStarteds的表,或者其他什么。如果您想保持内容的动态性,也就是说将其保存在数据库中以便更改,那么您就非常接近了,您可以使用自然语言模型,如“步骤”,并且步骤具有与它们相关联的顺序,然后您可以在getting started controller中根据其顺序查找步骤。您还可以使用带有steps控制器的普通工作流,然后使用:as=>
选项重命名路由中的路由
如果这些步骤是静态的,那么您可能希望探索一些可用的静态页面模型库,如high voltage