Forum: Ruby on Rails database table row creation method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
79092cfa5ae414d8f758d6b036f08d54?d=identicon&s=25 Renars S. (renars1985)
on 2009-03-08 10:42
I have following view for user input:

<h1>Post new thing</h1>
<%= form_tag :action => 'create' %>
<p><label for="thing_title">Title</label><br/>
<%= text_field 'thing', 'title' %></p>
<p><label for="thing_description">Description</label><br/>
<%= text_area 'thing', 'description' %></p>
<p><label for="thing_email">Email</label><br/>
<%= text_field 'thing', 'email' %></p>
<%= submit_tag "Create" %>
<%= form_tag %>


... and following controller that populates data (one row) in database

def create
@thing = Thing.new(params[:thing])
end


So far it is working. But I need to add one more parameter to @thing
variable that doesn`t come from user input. It comes from another model
(:another_main_thing_id). What is the syntax for adding this parameter
to @thing variable.
Thank you!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-08 15:11
(Received via mailing list)
On 8 Mar 2009, at 09:42, Renars Sirotins wrote:
>
> So far it is working. But I need to add one more parameter to @thing
> variable that doesn`t come from user input. It comes from another
> model
> (:another_main_thing_id). What is the syntax for adding this parameter
> to @thing variable.

There's an accessor  function created for you for each database
attribute

Fred
This topic is locked and can not be replied to.