0

编辑:第一个问题是我的前提本身。rails/html 是否应该在没有我明确要求的情况下生成“创建主题”按钮?

所以这是使用视图的控制器

class SubjectsController < ApplicationController

  def index
     list
    render('list')
  end

  def list
    @subjects = Subject.order("subjects.position ASC")
  end

  def show
    @subject = Subject.find(params[:id])
  end

  def new
    @subject = Subject.new(:name => 'default')
  end
  def create
    #instantiate a new object using form params
    @subject = Subject.new(params[:subject])
    #save the subject
    if @subject.save
      #if save succeeds redirect to list action
    else
      #if save fails, redisplay form
      render('new')
    end
  end
end

这是行为不端的视图(html.erb)文件,它没有生成我的按钮

<%= link_to("<< Back to List", {:action => 'list'}, :class => 'back-link') %>

<div class="subject new">
  <h2>Create Subject</h2>

  <%=  form_for(:subject, :url => {:action => 'create'}) do |f| %>

  <table summary="Subject form fields">
    <tr>
      <th>Name</th>
      <td><%= f.text_field(:name) %></td>
    </tr>
    <tr>
      <th>Position</th>
      <td><%= f.text_field(:position) %></td>
    </tr>
    <tr>
      <th>Visible</th>
      <td><%= f.text_field(:visible) %></td>
    </tr>
  </table>
<% end %>
</div>

目前,浏览器上的输出为:

'<< Back to List' (link)

<h2>Create Subject</h2>

Name     [blank-form]
Position [blank-form]
Visible  [blank-form]
[missing button location]

应该(根据 lynda.com)在缺少的按钮位置有一个显示“创建主题”的按钮,但它不存在。

4

1 回答 1

1

您的代码中的任何内容都不应该生成按钮。

您需要添加:

<%= f.submit 'Create Subject' %>

表格内。也许在</table>和之间<% end %>

于 2012-05-19T23:02:45.967 回答