场景:对正在操作的文章进行预览

#new.html.erb
<div class="form-group">
  <%= f.submit @article.new_record? ? "新建文章" : "文章更新", class: "btn btn-outline-secondary"%>
  <%= f.submit "文章预览", name: "preview", class: "btn btn-outline-secondary" %>
</div>

#articles_controller.rb
class ArticlesController < ApplicationController
  def create
    @article = Article.new(article_params)
    @article.user_id = params[:user_id]
    if params[:preview] || [email protected]
      render :new
    else
      redirect_to @article
      flash[:success] = "文章发布成功!"
    end
  end
end

results matching ""

    No results matching ""