Rails 5错误在视图上显示两次

时间:2017-10-26 02:21:08

标签: ruby-on-rails twitter-bootstrap

我刚刚在视图中添加了bootstrap样式到rails 5布局。错误呈现两次出现问题。如下图所示。enter image description here

在passangers控制器中,用于显示消息的逻辑"您已经有了乘车"如果布局页面在引导程序警报标记中显示错误消息,我不明白为什么要渲染两次。

passangers_controller:

def create
    @passenger = Passenger.new(passenger_params)
    @user = User.find(current_user.id)
    @transportation = Transportation.find(params[:transportation_id])
    @driver = User.find(@transportation.transporter_id)
    @protest = Protest.find(@transportation.destination_id)
    @transportations = Transportation.where(destination_id: @protest.id)
    has_ride = false

    @transportations.each do |transportation|
      passenger = Passenger.find_by user_id: current_user.id
      unless (passenger.nil?)
        has_ride = true
      end
    end

    if has_ride
      redirect_to protests_path, notice: "You already have a ride."
      return
    end

    respond_to do |format|
      if @passenger.save
        format.html { redirect_to user_protest_transportation_passenger_path(id: @passenger.id), notice: 'Passenger was successfully created.' }
      else
        format.html { render :new }
      end
    end
  end

这是views / protests / index.html.erb

<% if flash[:notice] %>
    <div class="notice"><%= flash[:notice] %></div>
  <% end %>

<div class="col-md-12">
  <div class="card">
    <div class="card-header">
      <h1>Protests</h1>
    </div>

    <div class="card-block", align="center">
      <% @protests.each do |protest| %>
        <div class="row">
          <div class="col">
            <h4 class="card-title"><%= protest.name %></h4>
          </div>
          <div class="col">
            <p class="card-img"><a href="/protests/<%=protest.id%>"><%= image_tag protest.image.url(:thumb), class: "img-thumbnail" %></a></p>
          </div>
        </div>
      <% end %>
    </div>
  </div>
</div>

0 个答案:

没有答案