Rails表单呈现两次

时间:2012-07-02 19:59:43

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 erb simple-form

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

由于

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>

enter image description here

1 个答案:

答案 0 :(得分: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