我是Rails的初學者。在閱讀文檔和教程時,我正在使用另一種語言(Java使用GeneXus生成)移植一個簡單的應用程序在View中執行對應於外鍵的值(執行應用程序)?
我正在構建員工輪班跟蹤器,所以我有兩個表:用戶和班次,與這些協會
class User < ActiveRecord::Base
has_many :shifts
end
class Shift < ActiveRecord::Base
belongs_to :user
end
我還在創建SQLite數據庫時在移位模型中添加了相應的user_id。
我的問題是,當試圖通過新視圖插入新記錄時,「user_id」字段不會正確驗證我嘗試寫入的任何有效user_id編號。我應該在這個領域插入什麼? (在Java中我的當前運行應用這一領域將接受USER_ID值)
當tryng插入「用戶」區域內的任何值,在「轉變」的看法,我收到以下錯誤
用戶(#63152640)預期,得到了 字符串(#19315740)
這裏的查看源代碼
new.html.erb
<h1>New shift</h1>
<%= render 'form' %>
<%= link_to 'Back', shifts_path %>
_form.html.erb
<%= form_for(@shift) do |f| %>
<% if @shift.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@shift.errors.count, "error") %> prohibited this shift from being saved:</h2>
<ul>
<% @shift.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :start %><br />
<%= f.datetime_select :start %>
</div>
<div class="field">
<%= f.label :end %><br />
<%= f.datetime_select :end %>
</div>
<div class="field">
<%= f.label :status %><br />
<%= f.text_field :status %>
</div>
<div class="field">
<%= f.label :user %><br />
<%= f.text_field :user %> //<-- What should I write here? User_id?
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
(所有這一切都與腳手架生成) 此外,在shifts_controller新的動作是
def new
@shift = Shift.new
end
顯示瀏覽源 – fl00r 2011-02-09 13:10:50
會做,因爲我回家 – bruno077 2011-02-09 13:22:46