[英]Rails + Paperclip: Nested attributes file_field form helper not working?
[英]Form helper using nested attributes
我必須管理具有帶有屬性“ user_id”的表的表單。 我想讓用戶寫一個他想直接邀請的人的名字,而不是使用id。
這是我的桌子
create_table "participations", :force => true do |t|
t.integer "event_id"
t.integer "user_id"
在我的參與模型中:
class Participation < ActiveRecord::Base
attr_accessible :event_id, :user_id,
belongs_to :event
belongs_to :user
end
用戶模型:
class User < ActiveRecord::Base
attr_accessible :id, :name,
has_many :participations
end
在您的表單中添加以下代碼:
<script>
$(document).ready(function() {
$('#user_auto_complete').typeahead({
name: 'user',
local: <%= @users.blank? ? [].to_json : raw (@users.map {|user| user.name }.to_json(:only => [:name ])) %>
});
});
</script>
<form>
<input type="text" id="user_auto_complete" name="user_id" value='<%= (!@participant.user_id.blank?)? "#{@users.find(@participant.user_id).name}" : ""%>'>
</form>
希望這個能對您有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.