选择提交按钮后,窗体视图不会在浏览器中重定向

时间:2013-10-03 19:53:32

标签: redirect ruby-on-rails-3.2

点击提交时,我的视图页面没有重定向。据我所知,我的服务器输出说重定向发生了。我通过更改控制器中的重定向位置来确认这一点。

Here's my server log of the cycle

以及我的相关文件。

class VenuesController < ApplicationController
  def index
    @venues = Venue.all
  end

  def new 
    @venue = Venue.new
  end

  def create
    @venue = Venue.create(params[:venue])
    if @venue.save
      redirect_to 'index' 
    else
      render 'new' 
    end
  end

  def show
    @venue = Venue.find(params[:id])
  end

  def edit
    @venue = Venue.find(params[:id])
  end

  def update
    @venue = Venue.find(params[:id])
    if @venue.update_attributes(params[:venue])
      flash[:success] = "Your venue has been updated"
      redirect_to 'show'
    else
      render 'edit', flash[:error] = "Unable to update venue"
    end
  end

  def destroy
    @venue = Venue.find(params[:id])
    @venue.destroy
    redirect_to venues_path
  end
end

如果查看上面的create方法,我将Venue.create更改为Venue.build。

Here are my logs for that attempt:

这是我的simple_form

<%= simple_form_for @venue, html: { class: 'form-horizontal' } do |f| %>
    <%= f.input :name, required: true %>
    <%= f.input :address, required: true %>
    <%= f.input :city, required: true %>
    <%= f.input :state, required: true %>
    <%= f.input :zip, required: true %>
    <%= f.input :description, label: "Provide a brief description of venue" %> 
    <%= f.button :submit %>
<% end %>

我的模特

class Venue < ActiveRecord::Base
  attr_accessible :description, :name, :address, :city, :state, :zip

  has_many :events
end

摘自我的示意图

 create_table "venues", :force => true do |t|
    t.text     "description"
    t.datetime "created_at",  :null => false
    t.datetime "updated_at",  :null => false
    t.string   "name"
    t.text     "address"
    t.string   "city"
    t.string   "state"
    t.string   "zip"
  end

我已经重新启动了我的服务器并从Webrick切换到瘦身。

回顾一下,我很难理解为什么一切看起来(至少对我的菜鸟眼睛来说)在我的日志中很好,但我的浏览器中没有重定向。

由于

1 个答案:

答案 0 :(得分:1)

而不是

redirect_to 'index'

redirect_to action: 'index'

供参考:

http://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-redirect_to