新手導軌,我想我可能忽略了一些非常簡單的東西,但我在部分顯示了一個表格兩次,不確定它是否與我的關聯有關。在部分導軌上顯示錶格兩次
這裏是屬性控制器:
class PropertiesController < ApplicationController
before_filter
def index
@property= Property.all
end
def new
@property = current_user.property.build if signed_in?
end
def show
@property = current_user.property.paginate(params[:page])
end
這裏是用戶控制器:
class UsersController < ApplicationController
before_filter :authenticate_user!
def index
authorize! :index, @user, :message => 'Not authorized as an administrator.'
@users = User.all
end
def show
@user = User.find(params[:id])
@property = @user.property.paginate(page: params[:page])
end
這裏有關聯的模型: 用戶模型:
class User < ActiveRecord::Base
has_many :property, dependent: :destroy
財產:
class Property < ActiveRecord::Base
attr_accessible :address, :name
belongs_to :user
這裏是_property.html.erb
部分
<li>
<table>
<tr>
<th>Name</th>
<th>address</th>
</tr>
<% @user.property.each do |property| %>
<tr>
<td><%= property.name %></td>
<td><%= property.address %></td>
</tr>
<% end %>
</table>
</li>
這裏是show.html.erb
<div class="row">
<aside class="span4">
<section>
<h1>
My Properties
</h1>
</section>
</aside>
<div class="span8">
<% if @user.property.any? %>
<h3>Properties (<%= @user.property.count %>)</h3>
<ol>
<%= render @property %>
</ol>
<%= will_paginate @property %>
<% end %>
</div>
</div>
這就是在瀏覽器中呈現。 http://i.imgur.com/SlilDo3.png
讓我知道是否還有其他方法可以幫助解決這個問題。所有回覆讚賞。
在您的用戶模型,你應該有'的has_many:properties',而不是'的has_many:property'。 – cortex
「SQL日誌」的第二部分看起來就像只顯示控制檯交互。你有沒有想要展示的東西? –
試圖編輯與圖像的問題不會讓我由於<10代表。以下是瀏覽器中呈現的內容http://i.imgur.com/SlilDo3.png – cyclopse87