使用carrierwave将“添加更多文档功能”添加到rails应用程序

时间:2019-04-29 14:47:25

标签: ruby-on-rails ruby-on-rails-5 carrierwave

我正在尝试使用carrierwave gem将添加更多文档的功能添加到我的rails应用程序中。 I am following this tutorial for it。我遇到了错误。

syntax error, unexpected ',', expecting keyword_end
syntax error, unexpected tLABEL

applicationshow.html.erb

<p>
  <span class="text-label">Client Last Name:</span>
  <%= @application.user.lastname %>
</p>

<p>
  <span class="text-label">Client First Name:</span>
  <%= link_to @application.user.firstname, user_path(@user) %>
</p>

<p>
  <span class="text-label">Clinic:</span>
  <%= @application.clinic_name %>
</p>

<p>
  <span class="text-label">Applicant name:</span>
  <%= @application.applicant_name %>
</p>

<p>
  <span class="text-label">Application Status:</span>
  <%= @application.status %>
</p>

<% @application.documents.each_with_index do |document, index| #grab the index %>
  <%= image_tag(document.url) %> 
  <%= link_to "Delete", user_application_document_path(@user, @application, index), :method => :delete, data: { confirm: "Are you sure you want to delete this document?", class: "btn btn-xs btn-danger" } %>
<% end %>


<%= form_for([@user, @application]), url: user_application_documents_path(@user, @application), method: :post do |f| %>
  <div class="field">
    <%= f.file_field :documents, multiple: true %>
  </div>
  <div class="actions">
    <%= f.submit "Add More Documents" %>
  </div>
<% end %>

documents_controller.rb

before_action :set_user
before_action :set_application

def create
    add_more_documents(documents_params[:documents])
    flash[:error] = "Failed uploading documents" unless @application.save
    redirect_back fallback_location: user_application_path(@user)
  end

private

def set_applicaion
  @applicaion = Applcation.find(params[:application_id])
end  

def set_user
    @user = User.find(params[:user_id])
end  

def add_more_documents(new_documents)
    documents = @application.documents 
    documents += new_documents
    @application.documents = documents
end

def documents_params
    params.require(:application).permit({documents: []})
end

请帮助我找到错误。该错误显示在表单上以添加更多文档。

1 个答案:

答案 0 :(得分:1)

这是一个简单的放错地方的括号。 form_for([@user, @application]),。它应显示为:

<%= form_for([@user, @application], url: user_application_documents_path(@user, @application), method: :post) do |f| %>