manny steele
manny steele

Reputation: 11

Cant find params (id)

Not really sure what going on or why the the provider id is comming back nil and it only comes back nil when trying to render provider_patient_access_path. I add a new pages to providers so the way it should be is localhost:3000/providers/id/patient_access

error message

   <!-- PROVIDERS SIDE MENU -->

    <%= link_to provider_patient_access_index_path(@provider.id) do %>
        <div class="side-menu-item">
        <div class="side-menu-icon" data-id="<%= @provider.id %>"><div id="side-menu-icon-search"></div></div>
        <div id="side-menu-item-text-patient-profiles" class="side-menu-item-text">Patient Access</div>
        </div><!--side-menu-item-->
    <% end %>

    <!-- ROUTES -->
    resources :providers do 
        resources :patient_access, only: [:index]
    end

    <!-- PROVIDERS_CONTROLLER -->
   class PatientAccessController < ApplicationController

    def index
        @provider = Provider.find(params[:provider_id])
        @active_patients = @provider.lists
        authorize @provider
    end
end
    end

Upvotes: 0

Views: 894

Answers (1)

3limin4t0r
3limin4t0r

Reputation: 21110

With those routes set up the path is going to be:

/providers/:id/patient_access(.format)

For this reason params[:provider_id] returns nil since it isn't provided, however params[:id] should return the correct value.

You can check your routes by visiting a non-existent URL/route in the development environment. For example http://localhost:3000/asdf. Or you can output them into the terminal using the command:

bundle exec rails routes

For more details about routing check the guide Rails Routing from the Outside In.

Upvotes: 2

Related Questions