Ejaye
Ejaye

Reputation: 31

Template is missing in Ruby on Rails using Active admin

I have an error in my project where in active admin it keeps on telling me missing template. Help on what to do what I want to happen is to be able to add a staff user in active admin

Missing template admin/vendor/update_add_staff, active_admin/resource/update_add_staff, active_admin/base/update_add_staff, inherited_resources/base/update_add_staff, application/update_add_cat with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :jbuilder, :slim, :csvbuilder]}. Searched in: /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"

Below is the codes:

Starting from admin/vendor.rb

the button "add" connects to the action item:

  action_item :edit_add_staff, only: [:show, :edit] do
    link_to('Add cat', edit_add_staff_admin_vendor_path(resource))
  end

then the action item connects to :

<%= 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 %>

then it is linked to:

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

and this is the routes:

 resources :vendors, only: [:show, :update] do
    resources :users,         controller: 'vendors/vendor_users' do
      member do
        post :update_add_staff

I hope someone can help me I don't really know what to do

Upvotes: 3

Views: 1433

Answers (1)

Amiel Martin
Amiel Martin

Reputation: 4814

@Pavel is right. Your member_action has an if statement. If u.staff_user == false, then it will redirect_to admin_vendor_path(resource), which I assume is working. Otherwise, no render or redirect has happened, so rails will default to attempting to render, and it will try to render the action update_add_staff.

To resolve this, you could add an else section to your if statement, or move the redirect_to outside of the if block.

# 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

Upvotes: 0

Related Questions