I have two models called ‘Page’ and ‘Area’
There relationships are as follows:
class Page < ActiveRecord::Base
has_many :areas
end
class Area < ActiveRecord::Base
belongs_to :page
attr_accessible :content, :name, :order, :title , :page_id
end
I have a view for creating the area in which I am accepting the page_id to associate the area to the page:
<%= f.label :page_id %><br /> #this is being interpreted incorrectly
<%= f.text_field :page_id %>
The form values in the action method are returned correctly with a page_id attribute. But on the html form the text value for the field is interpreted as “Page” rather than “page id”.
Irrespective of the fact that this may not be a good practice or there is a work around of manually changing the value of the label; I need to understand why is this happening. Can someone please explain. Even when I use the debugger within the new action method of the Area controller the object @area shows page_id attribute correctly. I am assuming f.label is doing something weird here.
I am using rails 3.2.7.
By default, Rails will drop the _id in labels. The next param in f.label is a string that will be the label’s inner html:
Outputs: