0

有时,当我提交表单然后返回浏览器时,它会呈现整个表单两次(参见屏幕截图)。不确定是我的视图或控制器代码导致了这种情况,但我似乎无法弄清楚。

谢谢

场合控制器.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>

在此处输入图像描述

4

1 回答 1

0

看起来您的用户有两个与之相关的场合。我会在您的控制器中使用 puts 语句检查场合的长度并检查您的日志:

  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
于 2012-07-02T20:05:51.967 回答