EDIT: The first question is my premise itself. Is rails/html SUPPOSED to generate a “Create Subject” button without me explicitly asking it to?
So here is the controller that is working with the view
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
And here is the misbehaving view (html.erb) file which isn’t generating my button
<%= 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>
Currently, the output on the browser is:
'<< Back to List' (link)
<h2>Create Subject</h2>
Name [blank-form]
Position [blank-form]
Visible [blank-form]
[missing button location]
There is supposed to (according to lynda.com) be a button which says “Create Subject” in the missing button location, but it’s not there.
Nothing in your code is supposed to generate a button.
You’ll need to add:
inside the form. Maybe between
</table>and<% end %>