0

I'm trying to setup a basic show method with a custom object called 'loan'. In my terminal I see the proper API request coming back with the object, however, I can't seem to call any of its attributes in the show.html.erb view. I've tried using resources :loans in my routes file. I've been successful in calling the Name field on the loan object the marketplace view but can't seem to get it to work in the show view.

I get the following error with the code below:

ActionView::Template::Error (undefined method `Name' for nil:NilClass):

routes.rb

match '/loans/:id', to: 'loans#show', :as => 'loan', via: [:get]

show.html.erb

<div class="container content">
  <div class="row">
    <div class="col-md-12">
      <h1><%= @loan.Name %></h1>
    </div>
  </div>
</div>

loans_controller.rb

class LoansController < ApplicationController
  before_filter :authenticate_user!
  include Databasedotcom::Rails::Controller

  def marketplace
    @loans = Loan__c.all
    @accounts = Account.all
  end

  def show
    render layout: 'lender'
    @loan = Loan__c.find(params[:id])
  end 

end

marketplace.html.erb

<h2><%= link_to loan.Name, loan_path(loan) %></h2>
Questifer
  • 1,113
  • 3
  • 18
  • 48

1 Answers1

0

The error was in the layout I had in the show controller:

render layout: 'lender'

I had broken ERB code in there.

Questifer
  • 1,113
  • 3
  • 18
  • 48