[英]Show method in Rails not working with databasedotcom gem
I'm trying to setup a basic show method with a custom object called 'loan'. 我正在尝试使用称为“贷款”的自定义对象设置基本的show方法。 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.
在终端中,我看到正确的API请求随对象一起返回,但是,我似乎无法在show.html.erb视图中调用其任何属性。 I've tried using resources :loans in my routes file.
我尝试在我的路线文件中使用resources:loans。 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 routes.rb
match '/loans/:id', to: 'loans#show', :as => 'loan', via: [:get]
show.html.erb 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 loan_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 marketplace.html.erb
<h2><%= link_to loan.Name, loan_path(loan) %></h2>
The error was in the layout I had in the show controller: 错误出在我在show控制器中的布局中:
render layout: 'lender'
I had broken ERB code in there. 我在其中破坏了ERB代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.