# Possible name clash?

**URL:** <https://www.ruby-forum.com/t/possible-name-clash/97491>\
**Category:** Rails\
**Created:** [July 7, 2006, 12:48pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491 "2006-07-07T12:48:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 12:48pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/1 "2006-07-07T12:48:38Z")

</div>

Scenario:

Table in database has two fields, id and category (table name is:  
categories)  
Controller is named category\_controller.rb  
Model is named category.rb  
Helper is named category\_helper.rb  
Form is named list.rhtml in view\category directory

The code in play on the form is (from generating scaffold):

\<% for category in @categories %\>

 \<%= h(category.category) %\> \<%= link\_to 'Show', :action =\> 'show', :id =\> category %\> \<%= link\_to 'Edit', :action =\> 'edit', :id =\> category %\> \<%= link\_to 'Delete', { :action =\> 'destroy', :id =\> category }, :confirm =\> 'Are you sure?', :post =\> true %\> \<% end %\>

link\_to on form is to action destroy

code that was in action in category\_controller (on first attempt that  
did not work):

cat = params[:category]

Problem is: cat was nil

Now I worked around it by doing this:

```
@category = Category.find(params[:id])
cat = @category.category

```

So, why if I can get the value of params[:id] from the form cannot I not  
also get the value of param[:category]?

Is it possible I am getting a name clash here? And if not a name clash,  
then of course the question becomes what might it be?

There doesn’t seem to be any confusion in the form with this line:

\<%= h(category.category) %\>  
But then the context seems such that there wouldn’t be, but perhaps the  
context is not so clear in the action in the controller?

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 1:33pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/2 "2006-07-07T13:33:34Z")

</div>

Hi Scott,

The reason the category is not available is that you are not passing  
it in your link\_to. To pass it just add a :category =\>  
category.category to your link\_to params.

This line: \<%= h(category.category) %\>  
will only display the category, but will not send it up when someone  
clicks on the links.

Tom

On 7/7/06, Scott H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> link\_to on form is to action destroy  
> @category = Category.find(params[:id])  
> But then the context seems such that there wouldn’t be, but perhaps the  
> context is not so clear in the action in the controller?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Tom D.

[http://atomgiant.com](http://atomgiant.com)  
[http://gifthat.com](http://gifthat.com)

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/3 "2006-07-07T14:08:40Z")

</div>

On Jul 7, 2006, at 6:48 AM, Scott H. wrote:

> 

> \<% end %\>
> 
> link\_to on form is to action destroy
> 
> code that was in action in category\_controller (on first attempt that  
> did not work):
> 
> cat = params[:category]
> 
> Problem is: cat was nil

when you have a construct like “:id =\> category”, the value given to  
the params[:id] is obtained from category.to\_param which is usuallly  
the same as category.id, that is, the primary key for the model.  
This particular bit of magic was clarified by Dave T. in response  
to my question last fall at a No Fluff Just Stuff conference (yeah,  
Java-centric, but a surprising amount of Ruby and Rails thrown in  
there).

-Rob

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 5:25pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/4 "2006-07-07T17:25:18Z")

</div>

Hi Scott,

Scott H. wrote:

> Anyway, I’m still somewhat confused as I could  
> have swore I read in one of my books that all the  
> field values on the form are returned and available  
> to the controller, automatically done for you and  
> each field then available to you through  
> params[:some\_name]. Did I misunderstand or  
> read it wrong?

Two related items seem to me to be at the root of your current problem,  
one  
of which you’ve already figured out. Forms are not pages, they’re  
‘containers’ (that are part of a page) that start and end with explicit  
tags. The second item is about ‘fields’. Your understanding above is  
correct. I think the problem you’re having here is your understanding  
of  
the term ‘field’. Your view contained no fields in the form-sense of  
the  
word. A form field is an object like a text\_field, a check\_box, a  
radio\_button, etc. The user-entered values of those things will be  
passed  
back to the controller in the params hash when the form is submitted.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/5 "2006-07-07T15:11:55Z")

</div>

Thanks Tom and Rob. Appreciate the response. I follow what you are both  
saying and I understand. I’m glad there is no name clash here as I have  
run into that previously, but that was too obvious - the table was named  
request! (I was just getting started.)

Anyway, I’m still somewhat confused as I could have swore I read in one  
of my books that all the field values on the form are returned and  
available to the controller, automatically done for you and each field  
then available to you through params[:some\_name]. Did I misunderstand or  
read it wrong?

This would be similar to a form bean, though it did take a call to make  
it happen, whereas I thought it was automatic in Rails.

If I understood that correctly, then is it different for this scenario  
because it is a list?

(Of course I am trying to locate where I got the idea from but so far  
have not been able to find it in the book.

Now, I am using partials with a layout template, and it just occurred to  
me that I do not have a start\_form\_tag(:action =\> …") in my partial  
form.

I hope this is making sense as I’m trying to deal here with a concept I  
thought existed but cannot find it at the moment.

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/6 "2006-07-07T17:56:29Z")

</div>

Bill W. wrote:

> Hi Scott,
> 
> Scott H. wrote:
> 
> > Anyway, I’m still somewhat confused as I could  
> > have swore I read in one of my books that all the  
> > field values on the form are returned and available  
> > to the controller, automatically done for you and  
> > each field then available to you through  
> > params[:some\_name]. Did I misunderstand or  
> > read it wrong?
> 
> Two related items seem to me to be at the root of your current problem,  
> one  
> of which you’ve already figured out. Forms are not pages, they’re  
> ‘containers’ (that are part of a page) that start and end with explicit  
> tags. The second item is about ‘fields’. Your understanding above is  
> correct. I think the problem you’re having here is your understanding  
> of  
> the term ‘field’. Your view contained no fields in the form-sense of  
> the  
> word. A form field is an object like a text\_field, a check\_box, a  
> radio\_button, etc. The user-entered values of those things will be  
> passed  
> back to the controller in the params hash when the form is submitted.
> 
> hth,  
> Bill

Thanks Bill. I get it now. I was confused and that cleared it up.

I just took a look now at my ‘new’ view and it does use the  
start\_form\_tag. Makes perfect sense and ties back in to what Tom and Rob  
said and I’ve got the big picture now with all three pieces.

Thanks guys. I needed all three pieces to understand this. Much  
appreciated.

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 7:07pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/7 "2006-07-07T19:07:22Z")

</div>

Hi Scott:

Scott H. wrote:

> Thanks Bill. I get it now. I was confused and that cleared it up.

Glad to help!

> I just took a look now at my ‘new’ view and it does use the  
> start\_form\_tag.

Don’t forget the end\_form\_tag. 😉

> Thanks guys. I needed all three pieces to understand this.  
> Much appreciated.

I’m sure I can safely speak for Tom and Rob too when I say… welcome  
aboard!

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 7, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/8 "2006-07-07T21:26:54Z")

</div>

Yes, welcome aboard Scott 🙂 I think you will find that this list is  
very helpful in getting you running with Ruby On Rails.

Good luck,

Tom

On 7/7/06, Bill W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Don’t forget the end\_form\_tag. 😉
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Tom D.

[http://atomgiant.com](http://atomgiant.com)  
[http://gifthat.com](http://gifthat.com)

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [July 8, 2006, 12:07am UTC](https://www.ruby-forum.com/t/possible-name-clash/97491/9 "2006-07-08T00:07:21Z")

</div>

Very much appreciate the welcome Bill and Tom; really do. It will take  
some time, but I am hoping to be able to contribute with being of help  
to others eventually as this is I think the greatest form of saying  
thank you. But it will be a while. In the mean time, for this out of  
work COBOLer/some Java, it means a lot to me to be able to get some help  
like this. And so I will try to make my questions good, well documented  
and understandable so that the question and the answers will be of  
benefit to others as well as myself.

So again, sincerely, thank you for the help and the welcome. 🙂 It’s  
good to be part of the RoR community.
