0

I am making a transition from Rails 2 to Rails 3.

_role_item.html.erb view:

    <% if @employee.has_role?(role.id) %>
        <%= link_to image_tag('pman/checkbox_unchecked.jpg'), action: 'add_role', :employee_id => @employee.id, :role_id => role.id %>
    <% end %>

Clicking the checkbox should assign a role to that Employee and redirect back to the partial page which contains a role_list and a privilege_list.

In my controller I have:

def add_role
        @employee = Employee::OldEmployee.find(params[:employee_id])
        @employee.add_role(params[:role_id])
        redirect_to :action => 'employee_privileges', :employee_id => @employee.id  
    end

The view which has both partials, _employee_privileges.html.erb:

<h3> <%= @employee.full_name %> (<%= @employee.initials %>) <%= @assign_roles %>  - PRIVILEGES & ACCESS</h3>

<br>

<table><tr><td valign=top>

    <%= render :partial => 'role_list' %>

</td><td width=50>
</td><td valign=top>

    <%= render :partial => 'privilege_list' %>

</td></tr></table>

<br>

employee_privileges.js.erb:

$("#roles").html("<%= j(render partial: 'employee_privileges') %>");

Function within controller:

def

employee_privileges
    @employee = Employee::OldEmployee.find(params[:employee_id])

    @roles = Acl::Role.find :all

    @modules = Acl::Module.find :all
    @module_privileges = Array.new
    @general_privileges = Acl::Privilege.find :all, :conditions => 'module_id IS NULL'
    if !@general_privileges.empty?
        @module_privileges << [nil, nil, nil, @general_privileges]
    end
    @modules.each do |m|
        if !m.privileges.empty?
            @module_privileges << [m.id, m.name, m.description, m.privileges]
        end
    end

    @assign_roles = flash[:assign_roles]
    #render :partial => 'employee_privileges'   
end

Currently, when clicking on the checkbox, I receive the error:

Missing template acl/acl/employee_privileges, application/employee_privileges with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/alex/Intranet_update/app/views"

Any help would be appreciated.

1 Answers1

0

Please provide the relative path in the for the partial you want to render.

$("#roles").html("<%= j(render partial: 'employee_privileges') %>");

option like render partial: '/folder_path/employe_privileges'

Sabyasachi Ghosh
  • 2,765
  • 22
  • 33
  • @MalusAlexandru have you provided the relative path for the file you want to access – Sabyasachi Ghosh Oct 24 '13 at 12:32
  • make It _employee_privileges.html.erb not _employee.privileges – Sabyasachi Ghosh Oct 24 '13 at 12:34
  • I tried with the base path like /acl/acl/_employee.privileges.html.erb and just _employee.privileges.html.erb . It is the same error and I think rails automatically knows the default path "Searched in: "/home/alex/Project/app/views"" because the controller has the folder acl and then the name acl_controller.rb – ROR senior dev Oct 24 '13 at 12:38
  • yes rails automatically check upto your view folder later you need to specify. – Sabyasachi Ghosh Oct 24 '13 at 12:45
  • just change the file name _employee_privileges.html.erb and check you have given wrong file name _employee.privileges.html.erb – Sabyasachi Ghosh Oct 24 '13 at 12:51
  • What exactly are you telling me to change? The line of employee_privileges.js.erb on the render partial? Because I did and the result is the same. Or maybe you're saying that I need to change the filename of either the view or this js to something else? Sorry, a bit confused.. – ROR senior dev Oct 24 '13 at 12:56