【问题标题】:rails redirect or render with a specific verbrails 使用特定动词重定向或呈现
【发布时间】:2011-05-25 18:55:22
【问题描述】:

我想在创建新项目时重定向到资源索引

这是控制器的一部分:

def create
    @asset = Asset.new(params[:asset])
    @assets = Asset.all
    respond_to do |format|
      if @asset.save
        format.html { render :action => 'index' } ##########
        format.xml  { render :xml => @asset, :status => :created, :location => @asset }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @asset.errors, :status => :unprocessable_entity }
      end
    end
  end

我感兴趣的行标记为##########

我试过了

  format.html { redirect_to(assets_url) }

还有一些其他的

它重定向到正确的位置并很好地创建了项目,问题是我无法将其设置为不是POST。我需要把它送到GET,否则它会对我的观点造成一些可怕的扭曲。

【问题讨论】:

    标签: ruby-on-rails-3 httpverbs


    【解决方案1】:

    redirect_to :action => :indexredirect_to assets_url 应该适合你。此外,index 操作始终是 GET 请求。执行rake routes 以查看控制器中每个操作的请求类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多