0

I am trying to implement the railscast (http://railscasts.com/episodes/217-multistep-forms?view=asciicast) within a modal window. I am receiving the fatal (exception reentered) error message after I click submit on my first page. I believe that it is getting stuck somewhere .next_step. I am using a modal window that calls new.js.erb and . I will add additional code as needed. Sorry for creating the question improperly. ---Code:

Model:
 estimate.rb
  class Estimate < ApplicationRecord
   attr_writer :current_step
   has_many :estimateitems
   def current_step
    @current_step || current_step.first
   end
   def next_step
    self.current_step = steps[steps.index(current_step + 1)]
   end
   def steps
    %w[1st 2nd]
   end
  end

 Views:
  new.js.erb
  // Add the dialog title
   $('#dialog h3').html("<i class='glyphicon glyphicon-plus'></i> New Estimate"); 
  // Render the new form
  $('.modal-body').html('<%= j render("clients/partials/form_create_estimate") %>');
  // Show the dynamic dialog
  $('#dialog').modal("show");
  // Set focus to the first element
  $('#dialog').on('shown.bs.modal', function () {
  $('.first_input').focus()
  })
  form_create_estimate.html.erb
   <%= form_for(@estimate, remote: true, :html => { :role => "form" }, :'data-update-target' => 'update-container') do |f| %>
    <% if @estimate.current_step = 1 %>
     <%= render '1st_step', :f => f %>
    <% elsif @estimate.current_step = 2 %>
     <%= render '2nd_step', :f => f %>
    <% end %>
    <div class="actions">
     <%= f.submit "Submit" %>
    </div>
  <% end %>

 Controllers:
  class EstimatesController < ApplicationController
   before_action :logged_in_user, only: [:index, :show, :edit, :update, :destroy]
   before_action :set_estimate, only: [:show, :edit, :update, :destroy]
   def index
    @estimates = Estimate.all
   end
   def show
   end
   def new
    @estimate = Estimate.new
   end
   def edit
   end
   def create
    @estimate = Estimate.new(params[:estimate_params])
    @estimate.next_step
    render 'new'
   end
   def update
    respond_to do |format|
     if @estiamte.update_attributes(estimate_params)
       format.json { head :no_content }
       format.js
     else
       format.json { render json: @estimate.errors.full_messages, status: :unprocessable_entity }
     end
    end
   end
   def destroy
    @estimate.destroy
    respond_to do |format|
     format.js
     format.html { redirect_to posts_url }
     format.json { head :no_content }
    end
   end
  private
   def set_estimate
    @estimate = Estimate.find_by(id: params[:id])
   end
   def estimate_params
    params.require(:estimate).permit(:nickname, :date)
   end
   # Confirms a logged-in user.
   def logged_in_user
    unless logged_in?
     store_location
     flash[:danger] = "Please log in."
     redirect_to login_url
   end
  end
 end
  • 1
    Include your code so we can look at it and help you identify the problem. The way your question is currently expressed is inappropriate for stackoverflow. The answer to it now is yes, we have successful experience with multi-step forms in a model window. But how does that help you if we can't look at your code? – user3456978 Oct 14 '16 at 15:50
  • Sorry about that. I am new to adding questions to stackoverflow. – Jeffrey Schaefer Oct 14 '16 at 16:43
  • Can you post stack trace from the log, when exception occurs ? – Sajan Oct 15 '16 at 06:10
  • seems you have a loop to stack overflow: https://stackoverflow.com/questions/26121671/what-does-this-rails4-error-mean-fatal-exception-reentered-rescue-in-roll – Малъ Скрылевъ Oct 16 '17 at 09:15

0 Answers0