Rails:如何在视图中确定控制器/动作 [英] Rails: How to determine controller/action in view
本文介绍了Rails:如何在视图中确定控制器/动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的部分表单:
<%= f.simple_fields_for :photo_attributes, :html => { :multipart => true } do |d| %>
<%= d.label :image, :label => 'Upload logo', :required => false %>
<%= d.file_field :image, :label => 'Image, :required => false', :style => 'margin-bottom:2px' %>
<%= d.input :image_url, :label => 'Billed URL', :required => false %>
<% end %>
如果操作是编辑,我想改为显示:
If the action is edit I want to show this instead:
<%= f.simple_fields_for :photo, :html => { :multipart => true } do |d| %>
<%= d.label :image, :label => 'Upload logo', :required => false %>
<%= d.file_field :image, :label => 'Image, :required => false', :style => 'margin-bottom:2px' %>
<%= d.input :image_url, :label => 'Billed URL', :required => false %>
<% end %>
我怎样才能做到这一点?
How can i achieve this?
推荐答案
一般表单部分只包含字段,不包含表单标签或字段,但是如果你没有其他方法,你总是可以看到什么params[:action]
当前设置为并相应地进行操作.
Generally the form partial only contains the fields, not the form tag or the fields for, but if you have no other way, you can always see what params[:action]
is currently set to and behave accordingly.
这篇关于Rails:如何在视图中确定控制器/动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文