我的项目中有一个错误,在活动管理员中,它不断告诉我缺少模板。我要做什么的帮助是能够在活动管理员中添加职员用户
缺少模板admin / vendor / update_add_staff, active_admin / resource / update_add_staff, active_admin / base / update_add_staff, Inherited_resources / base / update_add_staff,应用程序/ update_add_cat 与{:locale => [:en] 、: formats => [:html] 、: variants => [], :handlers => [:erb,:builder,:raw,:ruby,:coffee,:arb,:jbuilder, :slim,:csvbuilder]}。在以下位置搜索: / Users / James / work-files / apps / views “ /Users/james/.gem/gems/devise-4.0.3/app/views” * “ /Users/james/.gem/bundler/gems/apipie-rails-1f7d8419b7f4/app/views” * “ /Users/james/.gem/bundler/gems/activeadmin-09d00c2d9638/app/views” * “ /Users/james/.gem/gems/kaminari-core-1.1.1/app/views”
下面是代码:
从admin/vendor.rb
按钮“添加”连接到操作项:
action_item :edit_add_staff, only: [:show, :edit] do
link_to('Add cat', edit_add_staff_admin_vendor_path(resource))
end
然后将操作项连接到:
<%= simple_form_for([:admin, resource], url: update_add_staff_admin_vendor_path(resource), method: :put) do |f| %>
<div class="input text optional">
<label for="vendor_staff_users">Current Staff List</label>
<div class="indent-display">
<% resource.staff_users.each do |staff| %>
ID: <%= staff.id %> | <%= staff.full_name %> <br/>
<% end %>
</div>
</div>
<div class="input optional">
<label class="optional" for="vendor_staff_users">Staff ID</label>
<%= text_field_tag('vendor[staff_user]') %>
<span class="hint">Hint: Enter the staff user id</span>
</div>
<%= f.submit 'Add Staff' %>
<% end %>
然后将其链接到:
member_action :update_add_staff, method: :put do
u = User.find(params[:vendor][:staff_user])
if u.staff_user == false
u.staff_user = true
u.vendor_id = id
binding.pry
u.save
redirect_to admin_vendor_path(resource)
end
end
这是路线:
resources :vendors, only: [:show, :update] do
resources :users, controller: 'vendors/vendor_users' do
member do
post :update_add_staff
我希望有人能帮助我,我真的不知道该怎么办
答案 0 :(得分:0)
@Pavel是正确的。您的member_action
有一个if语句。如果为u.staff_user == false
,那么它将为redirect_to admin_vendor_path(resource)
,我认为这是可行的。否则,不会发生渲染或重定向,因此rails将默认为尝试渲染,它将尝试渲染动作update_add_staff
。
要解决此问题,您可以在if语句中添加else部分,或将redirect_to
移至if块之外。
# This should resolve the issue
member_action :update_add_staff, method: :put do
u = User.find(params[:vendor][:staff_user])
if u.staff_user == false
u.staff_user = true
u.vendor_id = id
binding.pry
u.save
else
flash[:error] = "Access denied"
end
redirect_to admin_vendor_path(resource)
end