多个附件在导轨4中编辑

时间:2014-10-01 13:34:12

标签: ruby-on-rails-4 carrierwave

我正在处理多个附件以存储在数据库中并进行编辑。但是我能够将多个文件存储到db。无法编辑。

        Other_assets_controller.rb

def create
    @other_asset = OtherAsset.new(other_asset_params)
    @other_asset.asset.company_id = current_company.id
    @other_asset.asset.identifier_id = current_user.id
    @other_asset.asset.asset_state_id = 1
    if @other_asset.save
       params[:attachments]['attachment_file'].each do |a|
       @attachment =@other_asset.attachments.create(:attachment_file => a)
       end
   redirect_to other_assets_path
   else
    render 'new'
    end
end

def update
   @other_asset = OtherAsset.find(params[:id])
   @attachments = @other_asset.attachments.find(params[:id])
   if @other_asset.update_attributes(other_asset_params)
      params[:attachments]['attachment_file'].each do |a|
      @attachment =@other_asset.attachments.create(:attachment_file => a)
      end
     redirect_to other_assets_path
   else
     render 'new'
   end
 end

def edit
     @other_asset = OtherAsset.find(params[:id])
end

other_assets / edit.html.erb

   <div class="sub-wrap-bg">
              <%= form_for(@other_asset) do |f| %>
                <%= render 'form', :f => f, :other_asset => @other_asset %>
                <div class="row">
                  <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12">
                    <div class="btn-group gr-btn save-file">
                      <%#= f.submit "Initiate Asset", :class => "orange_btn" %>
                      <%= f.submit "Update Other Asset", :class => "grey_btn" %>
                      <a class="black_btn" href="javascript:goBack()">Back</a>
                    </div>
                  </div>
                </div>

              <% end %>
        </div>

帮助我使用Rails 4和carrierwave gem

0 个答案:

没有答案