My error says:
No route matches {:action=>"new", :advertiser_id=>"2", :controller=>"analyses", :experiment_id=>nil} missing required keys: [:experiment_id]
Error happens in
app/views/analyses/index.html.erb:29:in `_app_views_analyses_index_html_erb___267178907_46340268'
Which points to this piece of code in my index.html.erb
<%= link_to 'New Analysis', new_advertiser_experiment_analysis_path(params[:experiment_id]) %>
The error also shows the parameters being passed as:
Parameters: {"advertiser_id"=>"9", "experiment_id"=>"2"}
Not sure why its telling me it doesnt know the experiment_id.
Here is my Analyses Controller
class AnalysesController < ApplicationController
before_action :set_analyses
before_action :set_analysis, only: [:show, :edit, :update, :destroy]
# GET experiments/1/analyses
def index
@analyses = @experiment.analyses
end
# GET experiments/1/analyses/1
def show
end
# GET experiments/1/analyses/new
def new
@analysis = @experiment.analyses.build
end
# GET experiments/1/analyses/1/edit
def edit
end
# POST experiments/1/analyses
def create
@analysis = @experiment.analyses.build(analysis_params)
if @analysis.save
redirect_to([@analysis.experiment, @analysis], notice: 'Analysis was successfully created.')
else
render action: 'new'
end
end
# PUT experiments/1/analyses/1
def update
if @analysis.update_attributes(analysis_params)
redirect_to([@analysis.experiment, @analysis], notice: 'Analysis was successfully updated.')
else
render action: 'edit'
end
end
# DELETE experiments/1/analyses/1
def destroy
@analysis.destroy
redirect_to experiment_analyses_url(@experiment)
end
private
# Use callbacks to share common setup or constraints between actions.
def set_analyses
@experiment = Experiment.find(params[:experiment_id])
end
def set_analysis
@analysis = @experiment.analyses.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def analysis_params
params.require(:analysis).permit(:conversion, :aov, :win_loss, :notes)
end
end