Adn*_*ota 7 ruby-on-rails ruby-on-rails-4
我有rails表单,使用字段列表呈现部分以创建新用户.那些我也用来渲染编辑表单的字段.我想知道是否有可能不在编辑表单上显示特定字段(即部门),因为我不想让用户选择更改部门?
Ahm*_*uty 12
你可以坚持使用吗?确保它不是将要插入的新记录甚至使用new_record的方法?如果记录未在数据库"新记录"中持久存在,则返回true的方法.ex :::
<%= f.text_field :department if @user.persisted? %>
or
<%= f.text_field :department unless @user.new_record? %>
Run Code Online (Sandbox Code Playgroud)
还有一种方法是检查操作本身,如果你从不同的视图渲染部分并且你想将它限制到特定的控制器,它也可以让你控制控制器,这些存储在::
params[:controller] -->> contains the name of the controller ex. UserController that you just hit on
params[:action] -->> contains the action name ex. new or edit
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4235 次 |
| 最近记录: |