我目前正在为图书馆管理系统做一个项目。我在项目中有五个表。它们都是相互关联的,即它们相互引用。
我正在处理的表格是Admin
, Books
, Library_Locations
,Users
和Categories
Books is referencing user,categories and admin .User is referencing library_location
我已经为它们创建了模型和控制器。我想知道我是否可以创建一个视图,这样如果我点击 book_id,我可以获得用户、类别和管理员的详细信息。
我的书表是:-
id serial NOT NULL,
title character varying(255) NOT NULL,
abstract character varying(255),
isbn character varying(255),
call_no character varying(255),
reference_no character varying(255),
category_id integer,
library_location_id integer,
author_first_name character varying(255),
author_middle_name character varying(255),
author_last_name character varying(255),
image character varying(255),
publisher character varying(255),
edition character varying(255),
book_location character varying(255),
deleted integer NOT NULL DEFAULT 0,
total_num_copies integer,
cost numeric(8,2) DEFAULT 0.0,
entered_by integer,
last_updated_by integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
CONSTRAINT books_pkey PRIMARY KEY (id)
我已经在 lov_names 和 values.The 上试过了。观点是:-
<h3>lov Name</h3><br>
<div class="span3">
<table class="table table-striped table-bordered">
<tr>
<td>Lov Names-Id: </td><td><%= params[:id] %></td>
<tr><td>Lov Names-Name:</td><td> <%= LovName.where('id = ?', params[:id]).pluck(:name)[0] %></td></tr>
<tr><td>Lov Values-Description:</td><td> <%= LovName.where('id = ?', params[:id]).pluck(:description)[0] %></td></tr>
</tr>
</table>
</div>
</br>
<table class="table table-hover table-bordered">
<tr><th>lov_value id.</td><th>lov_value Name</th><th>lov_value</th><th>Sequence</th><th>Edit</th><th>Delete</th></tr>
<% @lov_value.each do |p| %>
<tr>
<td><%= p.id %> <br></td>
<td><%= p.lov_name_id %> <br></td>
<td><%= p.lov_value %> <br></td>
<td><%= p.sequence %> <br></td>
<td><%= link_to 'Edit', {:action => 'lov_value_edit', :id => p.id} %> </td>
<td><%= link_to 'Delete', {:action => 'lov_value_delete', :id => p.id},
:data => { :confirm => "Are you sure you want to delete this lov_value?" } %></td>
</tr>
</tr>
<% end %>
</table>
<br/>
<p class="btn btn-primary "><%= link_to 'Back', {:action => 'index'} %></p>
<p class="btn btn-primary "><%= link_to 'Add New lov_values', {:action => 'add_values'} %></p>
我的 Books.rb 片段:-
has_many :book_holds
has_many :book_transactions
belongs_to :admin, :foreign_key => 'last_updated_by'
belongs_to :admin, :foreign_key => 'entered_by'
belongs_to :library_location
belongs_to :category
belongs_to :user
谁能给我一个关于如何实现这个的建议