I have seen a lot of similar routing issues and id=>nil posts, but none of the solutions have resolved my error.
First here is the entire error:
ActionController::UrlGenerationError in ProfileSteps#personal
Showing ...profile_steps/personal.html.erb where line #1 raised:
No route matches {:action=>"show", :controller=>"profile_steps", :id=>nil
I am using Wicked to create a multi step form and it seems like the I am not fetching the :id properly.
Here is the profiles_controller.rb following 'signup' and creating the 1st step of profile
def create
@profile = Profile.new(profile_params[:profile])
if @profile.save
session[:profile_id] = @profile.id
redirect_to profile_steps_path
else
render :new
end
end
Here is the profile_steps_controller.rb which is the next step of form it is redirected to
class ProfileStepsController < ApplicationController
include Wicked::Wizard
steps :personal
def show
@profile = Profile.new(params[:profile])
session[:profile_id] = @profile.id
render_wizard
end
def update
@profile = Profile.new(profile_params)
@profile.attributes = (profile_params)
render_wizard @profile
end
private
def profile_params
params.require(:profile).permit(:description, :name, :website)
end
def redirect_to_finish_wizard
redirect_to root_url, notice: "Thank you for signing up."
end
end
views/profile_steps/personal.html.erb
<%= form_for @profile, url: wizard_path do |f| %>
<br>
<div class="field">
<%= f.label :name, "Company Name" %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :website %><br>
<%= f.text_field :website %>
</div>
<br>
<div class="field">
<%= f.label :description %><br>
<%= f.text_field :description %>
</div>
<br>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
routes.rb
project::Application.routes.draw do
resources :profiles
resources :profile_steps
devise_for :users, :controllers => { :registrations => "registrations" }
root "pages#home"
get "profile" => "pages#profile"
match "profile_steps/personal", to: "profile_steps#personal", via: "post"
Thanks in advance and my apologies if this has been addressed in previous posts.
Updated:
Here is the 1st page of the multistep form:
new.html.erb
<%= form_for(@profile) do |f| %>
<% if @profile.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@profile.errors.count, "error") %> prohibited this profile from being saved:</h2>
<ul>
<% @profile.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<h1>New profile</h1>
<div>
<%= f.radio_button ..., true %> <%= f.label ... %>
</div>
<div>
<%= f.radio_button ..., false %> <%= f.label ... %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>