如何在不使用会话的情况下在控制器操作之间传递参数?

发布于 2024-10-08 08:56:17 字数 430 浏览 0 评论 0原文

例如,如果在我的“edit.html.erb”文件中我有这样的:

<%= form_for(@pjt_user) do |f| %> ……

 <%= fields_for(:new_pjt_user) do |b| %>
          <%= b.label :new_password %>
          <%= b.text_field :new_password %>
  <% end %>

​ <%结束%>

如何“预填充”/“填充”字段“new_password”(infields_for(:new_pjt_user)”)并使用渲染传递参数行动?我的目标是避免在会话中存储密码。

For example, if in my 'edit.html.erb' file I have this:

<%= form_for(@pjt_user) do |f| %>
...

 <%= fields_for(:new_pjt_user) do |b| %>
          <%= b.label :new_password %>
          <%= b.text_field :new_password %>
  <% end %>

...
<% end %>

How can I "pre-populate"/"fill" the field 'new_password' (in 'fields_for(:new_pjt_user)') passing a parameter with a render action? I aim to avoid to store password in session.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝戈者 2024-10-15 08:56:17

您必须使用 render :template 而不是 render :action ,这样您就可以使用 :locals 哈希:

render :template => "pjt_users/new", :locals => { :default_password => DEFAULT_PASSWORD }

<%= fields_for(:new_pjt_user) do |b| %>
  <%= b.label :new_password %>
  <%= b.text_field :new_password, :value => default_password %>
<% end %>

Instead of render :action you have to use render :template so you can use the :locals hash:

render :template => "pjt_users/new", :locals => { :default_password => DEFAULT_PASSWORD }

and

<%= fields_for(:new_pjt_user) do |b| %>
  <%= b.label :new_password %>
  <%= b.text_field :new_password, :value => default_password %>
<% end %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文