我正在使用旧数据库。
我有三个视图和控制器都有相同模型的输入,但这些控制器的数据略有不同。
当我使用“预付费”控制器时,数据将在PIN中,并且只有值存储在数据库中。但是,如果我使用“管理器”控制器,数据将存储用户名和引脚。
关于如何做到这一点,我一无所知,关于此问题,缺乏有关此问题的文档。
Radcheck Model
class Radchecks < ActiveRecord::Base
self.table_name = "radcheck"
belongs_to :user
attr_accessible :username, :value, :attribute, :op, :user_id
# alias_attribute = "attr", "attribute"
end
Managers controller
class ManagersController < ApplicationController
before_filter :authenticate_user!
def index
@managers = Radcheck.where(user_id:current_user.id)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @managers }
end
end
def create
@manager = Radcheck.new(radcheck_params)
@manager.user_id = current_user.id
respond_to do |format|
if @manager.save
format.html { redirect_to managers_path, notice: 'Manager has been added.' }
format.json { render json: @manager, status: :created, location: @manager }
else
format.html { render action: "new" }
format.json { render json: @manager.errors, status: :unprocessable_entity }
end
end
end
end
Manager view code
<div class="span7">
<table class="table">
<thead>
<tr>
<th></th>
<th>Username</th>
<th>Password</th>
<th></th>
</tr>
</thead>
<tbody>
<% @managers.each do |manager| %>
<tr>
<td><i class="icon-user icon-white"></i></td>
<td><%= manager.username %></td>
<td><%= manager.value %></td>
<td>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
manager,
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-mini btn-danger' %>
</td>
</tr>
</tbody>
<% end %>
</table>
<%= link_to t('.new', :default => t("helpers.links.new")),
new_manager_path,
:class => 'btn btn-primary' %>
</div>