Ruby on rails RubyonRails应用程序-使用sqlite3表记录动态生成html5选项标记

Ruby on rails RubyonRails应用程序-使用sqlite3表记录动态生成html5选项标记,ruby-on-rails,ruby,html,activerecord,Ruby On Rails,Ruby,Html,Activerecord,我试图用sqlite3创建一个安全模型 此代码位于../views/users内的_form.html.erb文件中/ 我有一个用户模型&一个用户级模型(管理员、用户等) 创建/编辑“用户”时,我希望能够从html5标记中选择“用户级别”值 当我试图查看页面时,我得到了nil:NilClass`的undefined方法desc' <%= form_for(@user) do |f| %> <% if @user.errors.any? %> <div i

我试图用sqlite3创建一个安全模型

此代码位于../views/users内的_form.html.erb文件中/

我有一个用户模型&一个用户级模型(管理员、用户等)

创建/编辑“用户”时,我希望能够从html5标记中选择“用户级别”值

当我试图查看页面时,我得到了nil:NilClass`的
undefined方法
desc'

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>
  <div class="field">
    <%= f.label :password %><br />
    <%= f.text_field :password %>
  </div>
  <div class="field">
    <%= f.label :user_level %><br />
    <select id="select_user_level">
      <%= @user_level.desc do |desc| %>
        <option value = "1"><%= desc %></option>
      <% end %>
    </select>
    <%= f.text_field :user_level %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

禁止保存此用户:



然后它就可以工作了,你不再需要@user\u级别了

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>
  <div class="field">
    <%= f.label :password %><br />
    <%= f.text_field :password %>
  </div>
  <div class="field">
    <%= f.label :user_level %><br />
    <select id="select_user_level">
      <%= @user_level.desc do |desc| %>
        <option value = "1"><%= desc %></option>
      <% end %>
    </select>
    <%= f.text_field :user_level %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
<%= f.collection_select :user_level, User::USER_LEVEL, :to_s :humanize %>
USER_LEVEL = ["admin", "mod", "user"]