Including an extra variable


#1

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:

Number
<%= text_field 'number', 'number' %>

Name
<%= text_field 'number', 'name' %>

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 S._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#2

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 S. 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:

Number
<%= text_field 'number', 'number' %>

Name
<%= text_field 'number', 'name' %>

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 S._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails