我是新來的鐵軌。我正在開發一個包含添加客戶的應用程序。在那裏我有下載按鈕。當我點擊下載按鈕時它應該在csv文件中下載當前客戶頁面。Rails如何只下載當前記錄點擊下載按鈕
控制器
def create
@customer_detail = CustomerDetail.new(customer_detail_params)
@customer_detail.company_profile_id = current_user.company_profile.id
respond_to do |format|
if @customer_detail.save
format.html { redirect_to edit_customer_detail_path(@customer_detail), notice: 'customerDetails was successfully created.' }
# format.html { render 'edit', notice: 'customerDetails was successfully created.' }
else
format.html { render :new }
end
end
end
def index
@customer_details = CustomerDetail.all
end
def destroy
end
def update
respond_to do |format|
format.html
format.csv { render text: @customer_details.to_csv }
if @customer_detail.update(customer_detail_params)
format.html { redirect_to @customer_detail, notice: 'customer_details was successfully updated.' }
else
format.html { render :edit }
end
end
end
查看
.fieldset
.row
.col-sm-3
= f.submit "Save", class: "btn btn-primary"
.col-sm-3
= f.submit "cancel", type: :reset, class: "btn btn-primary"
.col-sm-3
= link_to "Download", edit_customer_detail(format: "csv"), class: "btn btn-primary"
.col-sm-3
= link_to("Print", "javascript:print()", class: "btn btn-primary")
問題是,它從下載的形式的所有記錄。我不知道是否要更新或編輯行動。如果我給路徑edit_customer_detail而不是customer_details_(路徑)它顯示模板錯誤,並單擊下載按鈕時沒有路徑匹配錯誤。有人請幫助我。我是在這裏附上輸出鏈接。提前致謝!!
改變!。它表明了我的模板丟失的錯誤,如果我給customer_details_path。如果我給edit_customer_detail,沒有路線匹配。你能進一步幫助我嗎? –
= link_to「下載」,customer_details_path(格式:「csv」),類:「btn btn-primary」 –
我必須在我的代碼中替換?.in表單?或控制器?你可以詳細解釋一下 –