1

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 %>
user3435032
  • 23
  • 1
  • 4
  • It looks like you are setting the session id and then redirecting to the steps. After you are in the steps controller in show you are creating a new profile and setting the session. You should be loading you profile there based on the session. Also, you may want to post your routes. It looks like your route is expecting your id as well. – emcanes Jun 21 '14 at 13:22
  • Your error is due to this line -`<%= form_for @profile, url: wizard_path do |f| %>`. @profile hasn't been defined, so is nil, and that's breaking the url generator. I don't know anything about wicked_wizard - which action is running before the `personal` template is rendered? It's not clear to me from your code. – Max Williams Jun 21 '14 at 13:28
  • I think you need to read a little more about Rails. Something like this can happen in `new` action but not in `show` (unless you really know what you're doing) `@profile = Profile.new(params[:profile])` – Mike Szyndel Jun 21 '14 at 17:08
  • My advice is for you to go through Rails Guides and try understanding what you're doing first. Also, a tutorial like http://railsforzombies.org may help – Mike Szyndel Jun 21 '14 at 17:09
  • Max I included the first step of the multi form (new.html.erb). – user3435032 Jun 22 '14 at 06:33
  • @MichalSzyndel - I really appreciate the advice and I will continue to learn Rails moving forward. After speaking with several people one of the tips I received was to work on a project and to utilize the community to learn. I guess the advice was to learn from resolving bugs/issues. I will, however, continue the tutorials. I've finished OMR and I am completing Hartl so maybe I will have enough understanding of Rails to resolve my own issues. I will also check out railsforzombies. Thanks. – user3435032 Jun 22 '14 at 06:38

1 Answers1

0

I had this problem in the view on the first page of the wizard, I solved it using a helper method:

  def safe_previous_wizard_path(id)
    id ? previous_wizard_path : root_path
  end

or even:

  <% if applicant.persisted? %>
    <a href="<%= previous_wizard_path %>">Back</a>
  <% end %>
ecoologic
  • 10,202
  • 3
  • 62
  • 66