This isn''t a relational way to do it, but it is what you asked for...
def create
@user = your_code_for_however_you_get_your_user_if_necessary
@number = Number.new(params[:number])
@number.company = @user.company
@number.save
end
Martin Stabenfeldt wrote:> Hi,
>
> I?m adding numbers to a database from fields in a form, but I want to
> include some information I have in a variable not generated in this
> form.
> The variable user.company exists in the same class as create(), and I
> want to include the value of this variable when I add new numbers to
> the database.
>
> The form looks like this:
> <p><label
for="number_number">Number</label><br/>
> <%= text_field ''number'', ''number''
%></p>
>
> <p><label
for="number_name">Name</label><br/>
> <%= text_field ''number'', ''name''
%></p>
>
>
> def create
> @number = Number.new(params[:number])
> end
>
> How can I make "create" include the value of user.company or
$company?
> This should be put in the "company" field of the Numbers
database.
>
> Numbers contains the following fields: id, number, name, email, list,
> company
>
>
> Best regards,
> Martin Stabenfeldt_______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
--
Posted via http://www.ruby-forum.com/.