呜。我的第一个问题。

我有我俯瞰东西在我的形式建设非常基本的感觉。我使用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,这是在我的文档模型外键。我被困在这一夜,想不出什么今天上午新鲜。任何帮助将是巨大的。

有帮助吗?

解决方案

有关你需要的东西像profile_id

<%= f.hidden_field :profile_id %>

在哪个控制器,你会得到,如果需要使用params[:document][:profile_id]。 尽管从试图在你的代码是做猜测,我怀疑params[:profile_id]已经从什么途径得到你该控制器设置。

我不知道为什么你没有看到的任何说明。应该进入你的控制器params[:document][:description]

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top