2010-02-12 4 views
0

우입니다. 내 첫 번째 질문.attachment_fu 및 multipart form_for

나는 내 양식의 구성에서 아주 기본적인 것을 간과하고 있다는 느낌이 들었습니다. 나는 attachment_fu를 사용하고 있으며 파일 데이터 외에 아무것도 전달하지 못합니다. 사용자에게는 has_many 개의 프로필과 프로필에 has_many 개의 문서가 있습니다. ,

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 

로그가 모든 영상 데이터를 게시 점점 보여 주지만, 나는 나, 더 중요한 설명을 전달할 수 없습니다 :

<%= 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 -%> 

을 그리고 여기 컨트롤러의 :

내 양식은 다음과 같습니다 profile_id는 내 문서 모델의 외래 키입니다. 나는이 밤새 붙어 있었고, 오늘 아침에 신선한 것을 생각할 수 없다. 어떤 도움이라도 좋을 것입니다. 대한

답변

0

profile_id 당신과 같이해야합니다 : 컨트롤러에 당신이 필요한 경우 params[:document][:profile_id]를 사용하여 한 번에 얻을 것이다

<%= f.hidden_field :profile_id %> 

합니다. 당신의 코드가 무엇을하고 있는지 추측하려고 시도했지만, 나는이 컨트롤러에 당신을 연결시켜 준 경로에서 이미 params[:profile_id]이 설정되어 있다고 의심합니다.

왜 설명이 보이지 않는지 잘 모르겠습니다. 컨트롤러에 params[:document][:description]으로 입력되어야합니다.

+0

감사합니다. 아론. 맞습니다. profile_id는 경로를 통해 설정됩니다. 좀 더보고 있거나 놀아 본 후에 attachment_fu 플러그인과 질량 할당에 대한 방어 방법과 관련이 있다고 생각합니다. https://ar-code.lighthouseapp.com/projects/35/tickets/37-mass -assignment-attr_accessible 아직도 정확히 어떻게 처리해야할지 모르겠지만 시작은 ... – hellodally

+0

attachment_fu에 대한 특정 요구 사항이 있는지는 잘 모르겠지만 다루기가 더 쉽습니다. http :// /github.com/thoughtbot/paperclip –

+0

몇 시간 동안 attachment_fu를 가지고 놀았지만 뭔가를 가지고 있다고 생각했지만 그렇지 않았습니다. 클립은 끝내기 위해 어리석은 단순했다, 팁에 감사드립니다. – hellodally