在 Rails 编辑操作表单中,隐藏表单字段 [英] In Rails edit action form, hide a form field

查看:53
本文介绍了在 Rails 编辑操作表单中,隐藏表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Rails 应用程序,其中我不希望某些表单字段出现在我的编辑操作表单中.

I have a Rails application wherein I don't want some of the form fields to appear in my edit action form.

如何在 Rails 中执行此操作?

How can I go about doing this in rails?

推荐答案

一种可能性是使用 ActiveRecord 中的 persisted? 函数来检测表单对象是否已经持久化到数据库中,而不是一个新对象.

One possibility is to use the persisted? function in ActiveRecord to detect if the form object is already persisted to the database, rather a new object.

<%= form_for @user do |f| ->

  <%- if @user.persisted? %>
    <%# Will only show if @user has been saved to the database %>
    <%= f.text_field :some_attribute_to_show_during_edit %>

这篇关于在 Rails 编辑操作表单中,隐藏表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆