设置值时使用params渲染



我有一个链接,看起来像:

= link_to 'Issue?', "issues/new?desc=#{comment.body}"

在问题表单中,我选择desc参数来设置我的问题描述:

= form_for(@issue, :url => {:action => 'create',
   :controller => 'issues'}, :method => "post") do |f|
= f.text_field :title,
= f.text_area :description, value: params[:desc]

当我的问题验证失败时,问题就出现了。以下行由问题控制器触发:

format.html { render action: 'new' }

这会呈现用户输入的标题,但问题描述不会呈现,因为我正在用params[:desc]设置它的值。当触发render :new时,params[:desc]为零。如何在渲染期间在控制器中设置params[:desc]

路线:

get 'issues/new' => 'issues#new'
post 'issues/create' => 'issues#create'

desc更改为description:

= link_to 'Issue?', "issues/new?description=#{comment.body}"

然后以您的形式:

= f.text_area :description, value: params[:description]

或者你可以使用:

redirect_to new_issue_path(description: params[:description])

最新更新