【发布时间】:2013-07-15 01:11:08
【问题描述】:
在我的photos.rb 文件中,我有:
ActiveAdmin.register Photo do
form :partial => 'admin/forms/photo', :locals => { :events => Event.all }
end
在我的_photo.html.erb 文件中,我希望能够访问事件的值,但它似乎无法检测到。我该怎么做?
根据评论中的要求,这是我的表格:
<% if events.any? %>
<%= form_for [:admin, @photo], :validate => true do |f| %>
<!-- insert a bunch of standard field divs here -->
<div class="actions" style="margin-top: 20px">
<% if @photo.new_record? %>
<%= f.submit 'Create photo' %>
<% else %>
<%= f.submit 'Update photo' %>
<% end %>
</div>
<% end %>
<% else %>
<div style="font-size: 14px">
You cannot add photos until you have added at least one event.
</div>
<% end %>
我收到的错误消息在 events.any? 行附近:
Completed 500 Internal Server Error in 108ms
ActionView::Template::Error (undefined local variable or method `events' for #<#<Class:0x007fdb8e841b80>:0x007fdb8a93e7a8>)
【问题讨论】:
-
你也可以发布你的部分吗?
-
您在尝试访问此表单时是否在浏览器或控制台中出现错误?因为我看到您以正确的方式传递变量。如果您在日志中有任何错误,也请附上。
标签: ruby-on-rails-3 forms activeadmin