I've been battling for days now to get data to save for my nested form. I basically want to be able to store a users reason for cancelling a project, along with the last stage of the project before it was cancelled. But I just can't seem to get the actions `cancel`, `cancel_save`, and `cancel_params` to play nicely!

**Controller**

```
before_action :correct_user, only: [:show, :edit, :update, :destroy, :cancel, :cancel_save]

...

def cancel
  @project.build_project_close_reason
end

def cancel_save
  @project.build_project_close_reason(cancel_params)
  @project.update(project_status_id: 10)
  redirect_to root_path, notice: 'Project has been successfully cancelled.'
end

private 

def correct_user
  @user = current_user
  @project = current_user.projects.find_by(id: params[:id])
  end
  redirect_to user_projects_path, notice: "You are not authorised to view this project" if @project.nil?
end

def cancel_params
  params.require(:project).permit(project_close_reason_attributes: [:comment]).merge(project_close_reason_attributes: [project_id: @project.id, last_status_id: @project.project_status_id ])
end

```

**Models**

```
class Project < ApplicationRecord
  belongs_to :user
  has_one :project_close_reason
  accepts_nested_attributes_for :project_close_reason #adding this seemed to make no difference?
end

class ProjectCloseReason < ApplicationRecord
  belongs_to :project
end

class User < ApplicationRecord
... # All standard devise stuff
  has_many :projects
end

```

**Nested form in the view**

```
<%= form_for([@user, @project], url: {action: "cancel_save"}, method: :post) do |f| %>

<%= fields_for :project_close_reason do |pcr| %>

  <div class="field entry_box">
    <%= pcr.label "Why are you cancelling this project? (This helps us improve!)" %>
    <%= pcr.text_area :comment, class: "form-control entry_field_text" %>
  </div>

<% end %>

  <div class="actions center space_big">
    <%= f.submit "Cancel Project", class: "btn btn-lg btn-warning" %>
  </div>

<% end %>

```

**Routes**

```
devise_for :users
devise_for :admins

resources :users do
  resources :projects do
    get "cancel", :on => :member
    post "cancel" => 'projects#cancel_save', :on => :member
  end
end

```

This is the error I get when I try and submit the form:

`ActionController::ParameterMissing in ProjectsController#cancel_save
param is missing or the value is empty: project`. It references the `cancel_params` action

Thanks for any help!

UPDATE

Here is the log when I call `cancel_save`

```
Started POST "/users/2/projects/10/cancel" for ::1 at 2016-09-29 10:03:44 +0200
Processing by ProjectsController#cancel_save as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"h6K+VFyjW/dV189YOePWZm+Pmjey50xAMQIJb+c3dzpEaMv8Ckh3jQGOWfVdlfVH/FxolbB45fXvTO0cdplhkg==", "project_close_reason"=>{"comment"=>"b"}, "commit"=>"Cancel Project", "user_id"=>"2", "id"=>"10"}
User Load (11.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
Project Load (0.7ms)  SELECT  "projects".* FROM "projects" WHERE "projects"."user_id" = $1 AND "projects"."id" = $2 LIMIT $3  [["user_id", 2], ["id", 10], ["LIMIT", 1]]
ProjectCloseReason Load (0.2ms)  SELECT  "project_close_reasons".* FROM "project_close_reasons" WHERE "project_close_reasons"."project_id" = $1 LIMIT $2  [["project_id", 10], ["LIMIT", 1]]
Completed 400 Bad Request in 22ms (ActiveRecord: 12.1ms)

ActionController::ParameterMissing (param is missing or the value is empty: project):

```
['https://Stackoverflow.com/questions/39764678', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6748657/']
You need [`concat`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html):

```
print (pd.concat([df1[['Type','Breed','Behaviour']], 
                  df2[['Type','Breed','Behaviour']]], ignore_index=True))

             Type   Breed   Behaviour
0          Golden     Big         Fun
1           Corgi   Small       Crazy
2         Bulldog  Medium      Strong
3             Pug   Small      Sleepy
4  German Shepard     Big        Cool
5          Puddle   Small  Aggressive

```

More general is use [`intersection`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.intersection.html) for columns of both `DataFrames`:

```
cols = df1.columns.intersection(df2.columns)
print (cols)
Index(['Type', 'Breed', 'Behaviour'], dtype='object')

print (pd.concat([df1[cols], df2[cols]], ignore_index=True))
             Type   Breed   Behaviour
0          Golden     Big         Fun
1           Corgi   Small       Crazy
2         Bulldog  Medium      Strong
3             Pug   Small      Sleepy
4  German Shepard     Big        Cool
5          Puddle   Small  Aggressive

```

More general if `df1` and `df2` have no `NaN` values use [`dropna`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html) for removing columns with `NaN`:

```
print (pd.concat([df1 ,df2], ignore_index=True))
     Bark Sound   Behaviour   Breed Common Color Other Color            Type
0        NaN         Fun     Big         Gold       White          Golden
1        NaN       Crazy   Small        Brown       White           Corgi
2        NaN      Strong  Medium        Black        Grey         Bulldog
3         Ak      Sleepy   Small          NaN         NaN             Pug
4       Woof        Cool     Big          NaN         NaN  German Shepard
5         Ek  Aggressive   Small          NaN         NaN          Puddle               

print (pd.concat([df1 ,df2], ignore_index=True).dropna(1))
    Behaviour   Breed            Type
0         Fun     Big          Golden
1       Crazy   Small           Corgi
2      Strong  Medium         Bulldog
3      Sleepy   Small             Pug
4        Cool     Big  German Shepard
5  Aggressive   Small          Puddle

```
using `join` dropping columns that don't overlap

```
df1.T.join(df2.T, lsuffix='_').dropna().T.reset_index(drop=True)

```

[![enter image description here](https://i.stack.imgur.com/wb6AL.png)](https://i.stack.imgur.com/wb6AL.png)