<- TutorialScaffolding | [[Tutorial]] | TutorialFramingOut ->

In TutorialScaffolding, we saw how scaffolding can help us setup default actions as we develop our app, and we have overridden one of those defaults, show, which displays details about one person.  Our show method doesn't link back to the list action, or allow us to delete the record, which makes an unfriendly page.  Let's fix that.  

Add this to the *show.rhtml* file:

<pre>
<a href="/friends/list">List</a>
<a href="/friends/destroy/<%=@person.id%>">Delete</a>
</pre>

Hopefully by now you have an understanding of how rails rewrites URLs, but there is an easier way: use the "URL Helper":http://ap.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html .

You can replace those two lines with this:

<pre>
<%=link_to "List",  :action => "list" %>
<%=link_to "Delete", :action => "destroy", :id => @person.id %>
</pre>

and voila! Your links are created for you. 

If the link needs to specify a different controller, you can specify that as well, using :controller => "name".   Other options are also available.  There are a number of other useful helpers, which you can read about in the [[Helpers|documentation]].

Some of those predefined helper methods help with forms.  We need to build our own form to enter friend data, so let's take a look at them.  Start a new file in your editor, called *edit.rhtml*, in the views/friends directory.  Put this in there:

<pre>
<%= form_tag({ :action => "update" }) %>
<%= hidden_field "person", "id" %>
Name:
<%= text_field "person", "name", "size" => 20 %><br/>

Street:<br />
<%= text_field "person", "street1", "maxlength" => 20 %><br/>
<%= text_field "person", "street2", "maxlength" => 20 %><br/>
	
City:
<%= text_field "person", "city", "maxlength" => 20 %><br/>

State:
<%= text_field "person", "state", "maxlength" => 2 %><br/>

Zip:
<%= text_field "person", "zip", "maxlength" => 20 %><br/>

<input type="submit" value="Save">
</form>
</pre>

We now override the default scaffolding edit method in *friends_controller.rb* - this isn't necessary, but we will use this later in the tutorial:

<pre>
def edit
  @person = Person.find(@params["id"])
end
</pre>

Whaddaya know, you can edit the data!

Now we have a basic editing page!  Let's fill out the rest of the scaffolding methods in TutorialFramingOut.

Go to TutorialFramingOut | [[Tutorial]] | Back TutorialScaffolding

category:Tutorial
