# Using rails-generated code in "show"

**URL:** <https://www.ruby-forum.com/t/using-rails-generated-code-in-show/88591>\
**Category:** Rails\
**Created:** [March 12, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/using-rails-generated-code-in-show/88591 "2007-03-12T21:57:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [March 12, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/using-rails-generated-code-in-show/88591/1 "2007-03-12T21:57:47Z")

</div>

Hi!

I used scaffold to create my mvc for my table. I have only written  
one other ROR application, and since I was winging it, I didn’t take  
advantage of the rails-generate code.

My scenario is:

User clicks save on form, and is redirected to the “show” view where  
they see what they just saved. Code is this:

\<% session[:ward\_id] = @ward %\>

\<% for column in Ward.content\_columns %\>  
**\<%= column.human\_name %\>:**

```
<% if column.null == "true" %>

<% else %>

<%=h @ward.send(column.name) %>

```

\<% end %\>

\<% end %\>

My error is that beloved “you have a nil object when you didn’t expect  
it!”  
I am trying to check for nil values and have it just display nothing  
but the human\_name when it hits a nil. I have tried many different  
combinations and can’t seem to get it right. Any direction or  
suggestion is always appreciated!!

Thank you!!  
~~Ali

---

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [March 12, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/using-rails-generated-code-in-show/88591/2 "2007-03-12T23:04:56Z")

</div>

On Mar 12, 10:57 pm, “Ali” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ~~Ali  
> Probably you don’t pass the id parameter to the ‘show’ controller

You have to do something like this after the creation of the object:

redirect\_to :action =\> ‘show’, :id =\> myobject.id

---

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [March 13, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/using-rails-generated-code-in-show/88591/3 "2007-03-13T17:42:56Z")

</div>

On Mar 12, 3:03 pm, “Trochalakis C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Thank you!!  
> > ~~Ali
> 
> Probably you don’t pass the id parameter to the ‘show’ controller
> 
> You have to do something like this after the creation of the object:
> 
> redirect\_to :action =\> ‘show’, :id =\> myobject.id

Yep, that did it!! Thanks a bunch!!  
~Ali
