# New entries from foreign controller

**URL:** <https://www.ruby-forum.com/t/new-entries-from-foreign-controller/109702>\
**Category:** Rails\
**Created:** [July 18, 2007, 4:40am UTC](https://www.ruby-forum.com/t/new-entries-from-foreign-controller/109702 "2007-07-18T04:40:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 18, 2007, 4:40am UTC](https://www.ruby-forum.com/t/new-entries-from-foreign-controller/109702/1 "2007-07-18T04:40:25Z")

</div>

I have a situation that I can’t seem to find an answer for. I have a  
view for a new “report” I want it to be possible for the user to input  
a company name and location if they aren’t already in the list of  
“known” values and when the form is submitted I want those manual  
entries added to their respective tables at the same time the report  
is added.

How would I go about doing this? I’ve tried creating new\_company and  
new\_location fields in the view and looking for them in the controller  
but they are never set in the params hash.

Below is the relevant code:

CONTROLLER:

def create  
@report = Report.new(params[:report])

```
# If they entered a location that wasn't listed we need to add it
if params[:new_location]
  @location = Location.new
  @location.city = params[:new_location][0]
  @location.region = params[:new_location][1]
  @location.country = params[:new_location][2]
  @location.save
end

# Similar to above but if they entered a company that wasn't lited
if params[:new_company]
  @company = Company.new
  @company.name = params[:new_company]
  if params[:new_location]
    @company.location_id = @location.id
  end
  @company.save
end

# And again for a new position
if params[:new_position]
  @position = Position.new
  @position.name = params[:new_position]
  if params[:new_company]
    @position.company_id = @company
  end
  @position.save
end

if @report.save
  flash[:notice] = params.to_s
  redirect_to :action => 'list'
else
  render :action => 'new'
end

```

end

VIEW:

Title  
 \<%= text\_field 'report', 'title' %\>

Company: \<%= options\_from\_collection\_for\_select(@companies, :id, :name, @selected) %\>

Other: \<%= text\_field 'report', 'company\_id' %\>

Position: \<%= options\_from\_collection\_for\_select(@positions, :id, :name, @selected) %\>

Other: \<%= text\_field 'report', 'position\_id' %\>

Category: \<%= options\_from\_collection\_for\_select(@categories, :id, :name, @selected) %\>

Other: \<%= text\_field 'report', 'category\_id' %\>

Thanks in advance,  
Glen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 18, 2007, 5:12am UTC](https://www.ruby-forum.com/t/new-entries-from-foreign-controller/109702/2 "2007-07-18T05:12:29Z")

</div>

Nevermind, I should have poked it with the “stick” a few more times  
before I posted.

Using \<%= text\_field\_tag ‘new\_thing’ %\> rather than \<%= text\_field  
‘report’, ‘thing’ %\> gave me the values in params I was looking for.

On Jul 17, 8:39 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
