简体   繁体   English

Rails形成重定向到“新”动作

[英]Rails form redirecting to 'new' action

What I am trying to do is build a form in which the user fills some of the fields for a new Publication, and takes you to the New Publication action, with those fields already filled in, so the user fills the rest. 我要做的是构建一个表单,其中用户填写新发布的一些字段,并带您进入新发布操作,这些字段已经填写,因此用户填写其余部分。

I got the controller part covered, but I cant find how to use form_for for this, as its not exactly associated to the model (only some of the necessary fields are in the first form). 我得到了控制器部分,但我无法找到如何使用form_for,因为它与模型没有完全关联(只有一些必要的字段在第一种形式)。

你能做到的

form_tag new_publication_path()

Not necessarily the best way to do this, but you can hide some of the fields in the form depending on whether the model id is valid. 不一定是执行此操作的最佳方法,但您可以隐藏表单中的某些字段,具体取决于模型ID是否有效。 For example (in haml): 例如(以haml为单位):

- if @model.id #only shows up if the model has been saved.
  = f.text_field :field_name, ...

This way you can use the usual new, and then when the model has been saved, just redirect to the 'edit' action and the rest of the fields show up. 这样您就可以使用常用的new,然后在保存模型时,只需重定向到“edit”操作,其余字段就会显示出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM