运行下面的代码时,我得到以下异常:
uninitialized constant ActionView::CompiledTemplates::Current
控制器:
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :finishing_step
def show
@user = Current.user
render_wizard
end
def update
render_wizard
end
private
def finish_wizard_path
current_user.update_attributes(complete: true)
redirect_to root_path
end
end
形式:
<%= form_for Current.user, url: wizard_path do |f| %>
<div><%= f.label :first_name, "First Name" %><br />
<%= f.text_field :first_name %></div>
<div><%= f.label :middle_name, "Middle Name" %><br />
<%= f.text_field :middle_name %></div>
<div><%= f.label :last_name, "Last Name" %><br />
<%= f.text_field :last_name %></div>
<div><%= f.label :phone_number, "Phone Number" %><br />
<%= f.text_field :phone_number %></div>
<div><%= f.label :date_of_birth, "Date of Birth" %><br />
<%= f.date_select :date_of_birth, start_year: 1900 %></div>
<div><%= f.label :address_first_line, "Address (first line)" %><br />
<%= f.text_field :address_first_line %></div>
<div><%= f.label :address_second_line, "Address (second line)" %><br />
<%= f.text_field :address_second_line %></div>
<div><%= f.label :city, "City" %><br />
<%= f.text_field :city %></div>
<div><%= f.label :nationality, "Nationality" %><br />
<%= country_select(:user, :nationality, {selected: "UG"}) %></div>
<div>
<%= f.label :avatar %>
<%= f.file_field :avatar %>
</div>
<div>
<%= f.label :terms_of_service, "Agree to Terms of Service" %> <br>
<%= f.check_box :terms_of_service %>
</div>
<div><%= f.submit "Register" %></div>
<% end %>
<%= render "devise/shared/links" %>
答案 0 :(得分:1)
问题是导轨无法找到您在Current
中使用的课程form_for
。它正在查看视图的命名空间,这就是为什么你会得到稍微神秘的错误消息。如果肯定有一个班级Current
,那么您可以使用::Current.user
访问它,但我怀疑它不存在。
通常使用设计方法current_user
访问当前用户。值得仔细检查您应该如何访问当前用户。