Ich bin neu bei Schienen. Im Entwickeln einer App, die das Hinzufügen von Kunden enthält.In, dass ich Download-Button habe. Wenn ich auf Download-Button klicken Es sollte die aktuelle Kundenseite in CSV-Datei herunterladen.Schienen, wie nur aktuellen Datensatz herunterladen, wenn geklickt Download-Taste
-Controller
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
Ansicht
.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")
Das Problem ist es aus der Form alle Datensätze herunterlädt. Ich weiß nicht, ob zur Aktion in Update oder Edit gegeben werden soll. Wenn ich den Pfad edit_customer_detail anstelle von customer_details_ (Pfad) gibt es Vorlage Fehler und keine Route entspricht Fehler beim Klicken auf download button.can jemand bitte helfen Sie mir.Ich habe habe den Output-Link hier angehängt. Danke im Voraus!!
verändert eine Antwort hinzugefügt haben! .Es zeigt mir Vorlage fehlt Fehler, wenn ich customer_details_path geben. Und keine Route stimmt überein, wenn ich edit_customer_detail gebe. Kannst du mir weiter helfen? –
= link_to "Download", customer_details_path (format: "csv"), klasse: "btn btn-primary" –
wo muss ich in meinem code ersetzen? .in form? oder Controller ?. Kannst du kleine Details erklären –