我需要一种方法来将我所做的方法应用于我选择的订单。或者找到另一种方法来标记某些内容。
这是我到目前为止所尝试的。但我不介意尝试一些全新的东西。 所以我有这些订单,我在视图中显示如下:
.col-md-12
.admindash
%h1 Admin Dashboard
.text-norm
Welcome to the admin dashboard here you can see incoming and outgoing orders.
.row
.col-md-8
- for order in @order
%h2
= order.user.name
.orderpanel
.clientarea
Client name:
= order.user.name
%br
Client email:
= order.user.email
%br
Client address ... -->:
%br
= order.user.address_line_1
%br
= order.user.address_line_2
%br
= order.user.postcode
%br
= order.user.city
%br
= order.user.country
.delivarea
%br
delivery_name:
= order.delivery_name
%br
company_name:
= order.company_name
%br
delivery_address1:
= order.delivery_address1
%br
delivery_address2:
= order.delivery_address2
%br
delivery_address3:
= order.delivery_address3
%br
delivery_city:
= order.delivery_city
%br
delivery_postcode:
= order.delivery_postcode
%br
phone:
= order.phone
%br
package_contents:
= order.package_contents
%br
description_content:
= order.description_content
%br
contents_value:
= order.contents_value
%br
cf_reference:
= order.id
CR
%br
reference_number:
= order.reference_number
.tac
restricted_items:
= order.restricted_items
%br
terms_conditions:
= order.terms_conditions
%br
insurance:
= order.insurance
= order.id
.col-md-4.sidebar
= paginate @order
= link_to "Data Control", rails_admin_path, :class => 'btn-danger btn'
%p
= link_to "Back to Dashboard", :back, :class => 'btn-danger btn'
我想在页面上添加一个按钮,以便我可以标记订单完成,也可以创建一个包含所有订单的表格和一个标记为完整的按钮。
所以我运行了一个迁移来添加布尔类complete
。
class AddCompleteToOrder < ActiveRecord::Migration
def change
add_column :orders, :complete, :boolean, default: false
end
end
然后在命令控制器中我做了:
def complete
order = Order.find(params[:order_id])
order.complete!
# handle response
end
order.rb
class Order < ActiveRecord::Base
belongs_to :user
def complete!
update(complete: true)
end
end
的routes.rb
Rails.application.routes.draw do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
get 'home/index'
root 'home#index'
#pages
get '/why' => 'pages#why'
get '/trak' => 'pages#trak'
get '/contact' => 'pages#contact'
get '/mydms' => 'pages#mydms'
get '/air' => 'pages#air'
get '/ocean' => 'pages#ocean'
get '/road' => 'pages#road'
get '/courier' => 'pages#courier'
get 'fulfilment' => 'pages#fulfilment'
get 'express' => 'pages#express'
resources :dashboard
get 'dadmin' => 'dashboard#dadmin'
get 'myorders' => 'dashboard#myorders'
get 'label' => 'dashboard#label'
resources "contacts", only: [:new, :create]
devise_for :users
as :user do
get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
put 'users' => 'devise/registrations#update', :as => 'user_registration'
end
resources "orders"
get "confirm" => "confirmations#show"
get 'dconfirmation' => 'orders#confirmation'
end
所以我现在需要一些方法来更新特定的订单。像列出所有订单@ order.id然后选择该订单以使用该方法。因为我是Rails的新手,所以我不知道自己在做什么。请帮忙。我只需要表明订单现已完成。
我不介意如何将订单标记为完整,如果页面重新加载并且我的网站确实使用jQuery,则只需记住这一点。有没有一种方法可以做到这一点?