0
Woo。我的第一個問題。attachment_fu和multipart form_for
我有一種感覺,我在我的表單構造中忽略了一些非常基本的東西。我正在使用attachment_fu,並且無法通過此表單傳遞除文件數據之外的任何內容。用戶has_many配置文件和配置文件has_many文件。
我的形式如下:
<%= error_messages_for :document %>
<% form_for([@user, @profile, @document], :html => {:multipart => true }) do |f| -%>
<p>
<label for="document">Upload A document:</label>
<%= f.file_field :uploaded_data %>
</p>
<%= f.label :description%>
<%= f.text_field :description%>
<p>
<%= submit_tag 'Upload' %>
</p>
<% end -%>
而這裏的控制器:
before_filter :require_user, :get_profile
def new
@document = @profile.documents.build
end
def create
@document = @profile.documents.build(params[:document])
if @document.save
flash[:notice] = 'Your document was successfully created.'
redirect_to document_url(@document)
else
render :action => :new
end
end
private
def get_profile
@user = current_user
@profile = @user.profiles.find(params[:profile_id])
end
該日誌顯示所有圖像數據得到公佈,但我不能,或者更重要的是通過描述, profile_id,它是我的文檔模型中的外鍵。我整晚都陷在這裏,今天早上想不出什麼新鮮事。任何幫助都會很棒。
謝謝Aaron。你是對的,profile_id是通過路線設置的。 經過更多的觀看/玩耍之後,我認爲它與attachment_fu插件以及它抵禦大規模作業的方式有關:https://ar-code.lighthouseapp.com/projects/35/tickets/37-mass -assignment-attr_accessible 我仍然不確定如何處理它,但它是一個開始... – hellodally 2010-02-13 00:21:36
不確定您是否對attachment_fu有任何特定要求,但是您可能會發現回形針更容易處理:http:/ /github.com/thoughtbot/paperclip – 2010-02-13 04:06:35
附帶_fu玩了幾個小時,以爲我有東西,但沒有。回形針是愚蠢的 - 簡單得走,謝謝你的提示。 – hellodally 2010-02-16 19:46:56