简体   繁体   中英

Rails Form Renders Twice

Sometimes when i submit a form and then go back in my browser it renders the entire form twice (see screenshot).. Not sure if its my view or controller code causing this but i cant seem to figure it out.

Thanks

occasions_controller.rb

  def create
     @user = current_user
     @occasion = Occasion.new(params[:occasion])
     @occasion.user = User.find(current_user.id)
     if @occasion.save
      redirect_to occasions_path
    else
      render :new
    end
  end

user_steps/occasions.html.erb

<%= simple_form_for @user, url: wizard_path do |f| %>
  <div id="single_module">
  <div class="pitch">
   <h2 class="signup">Step 3: Your first Occasion!</h2>
  </div>
  <div id="input1" style="margin-bottom:4px;" class="clonedInput">
    <p>*Just one to get you started, after completion of the sign up process you will have a chance to utilize our occasion wizard to add as many events as you like! (exciting, we know)</p>
    <ul class="testss1">
      <%= f.simple_fields_for :occasions do |occasion_o| %>
        <li><%= occasion_o.input :name, :placeholder => 'Enter occasion Name', :hint => ('Examples: Anniversaries, Birthdays, Graduations, Mothers day, Fathers day, Valentines day, Weddings, Holidays') %></li>
        <li><%= occasion_o.input :pname, :label => 'Persons Name', :placeholder => '(optional)' %></li>
        <li><%= occasion_o.input :dateg, :label => 'Date',:as => :date_picker, :input_html => { :class => 'special' } %></li>
        <li><%=  occasion_o.input :recurring, :as => :radio_buttons, :label => 'Remind me of this event every year?' %></li>
    <h3>Top 3 Interests</h3>

        <li class="tes1"><%= occasion_o.association :interests, :label => false, :as => :check_boxes %></li></ul>
    <%end%>
    </br>
    </div>
      <%= link_to "skip this step", next_wizard_path %>
      <%= f.button :submit, 'Submit' %>
     </br>
     </br>
     </br>

在此处输入图片说明

It looks like your user has two occasions tied to it. I would check the length of the occasions with a puts statement in your controller and check your log:

  def create
     @user = current_user
     puts "The current length of occasions is #{ @user.occasions.length }"
     @occasion = Occasion.new(params[:occasion])
     @occasion.user = User.find(current_user.id)
     if @occasion.save
      redirect_to occasions_path
    else
      render :new
    end
  end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM