# Edit HMT with fields\_for

**URL:** <https://www.ruby-forum.com/t/edit-hmt-with-fields-for/177117>\
**Category:** Rails\
**Created:** [October 12, 2009, 12:37am UTC](https://www.ruby-forum.com/t/edit-hmt-with-fields-for/177117 "2009-10-12T00:37:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [October 12, 2009, 12:37am UTC](https://www.ruby-forum.com/t/edit-hmt-with-fields-for/177117/1 "2009-10-12T00:37:07Z")

</div>

Hi,  
I have 3 models:

hotel  
has\_many :ratings  
has\_many :categories, :through =\> :ratings

category  
has\_many :ratings  
has\_many :hotels, :through =\> :ratings

rating  
belongs\_to :hotel  
belongs\_to :category

I have categories like food, rooms etc. that I want to rate in my  
hotel edit view:  
…  
\<% if @hotel.categories.any? %\>  
\<% @hotel.ratings.each do |rating| %\>  
\<% fields\_for @hotel.ratings do |rating\_form| %\>

- \<% rating.category.name %\> \<% rating\_form.text\_field :rating  
%\>
  
\<% end %\>  
\<% end %\>  
…

Unfortunately this doesn’t work.

Any help would great.

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [October 12, 2009, 10:57am UTC](https://www.ruby-forum.com/t/edit-hmt-with-fields-for/177117/2 "2009-10-12T10:57:02Z")

</div>

> …  
> \<% if @hotel.categories.any? %\>  
> \<% @hotel.ratings.each do |rating| %\>  
> \<% fields\_for @hotel.ratings do |rating\_form| %\>
> 
> - \<% rating.category.name %\> \<% rating\_form.text\_field :rating  
> %\>
>   
> \<% end %\>  
> \<% end %\>  
> …

As you told you are trying to edit hotel information. So I think you  
should have like following  
\<% form\_for(@hotel) do |form| %\>  
\<% end %\>

and inside this you might use like  
\<% form.fields\_for :ratings do |rating\_field| %\>  
# print rating fields  
\<% end %\>

If the above doesnt help you, would you please provide more insight  
about what and how you are actually want to print ratings in hotel  
edit form?

Thank you.

Samiron paul

> **[Small Talk](https://samironpaul.blogspot.com/)**

[http://www.code71.com](http://www.code71.com)

---

<div class="post-metadata">

**Author:** ![arwed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/54ee81/32.png) [@arwed](https://www.ruby-forum.com/u/arwed)\
**Post date:** [October 12, 2009, 2:53pm UTC](https://www.ruby-forum.com/t/edit-hmt-with-fields-for/177117/3 "2009-10-12T14:53:31Z")

</div>

Hi Paul,

thanks for your reply.

In my categories table I have some records: rooms, food, service etc.

my show.html.erb looks like this:

## Hotel Ratings:
\<% @hotel.ratings.each do |show| %\> - For a hotel this gives me:
