ruby - Rails mark an order order as complete. This order is made from a form -


hello there im new rails appreciate on matter.

im looking way mark order complete. example of have list of orders admins can view following code.

.row   .col-md-8     - 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 

is there way of selecting order name or id. adding new completed field thew migration orders. clicking button setting value true. sorry im new rails , wonder if there way this.

here orders controller:

class orderscontroller < applicationcontroller   before_filter :authenticate_user!   def new     @order = order.new   end    def create     @order = current_user.orders.new(order_params)     @order.email = current_user.email     @order.name = current_user.name     @order.address_line_1 = current_user.address_line_1     @order.address_line_2 = current_user.address_line_2     @order.postcode = current_user.postcode     @order.city = current_user.city     @order.country = current_user.country     if @order.save       redirect_to dconfirmation_path     end   end    def order_params     params.require(:order).       permit(         :email,         :delivery_name,         :company_name,         :delivery_address1,         :delivery_address2,         :delivery_address3,         :delivery_city,         :delivery_postcode,         :delivery_country,         :phone,         :package_contents,         :description_content,         :restricted_items,         :terms_conditions,         :insurance,         :contents_value,         :cf_reference,         :reference_number         )   end   def show     @user = user.find(params[:id])   end    def confirmation   end  end 

thank viewing post regularly. if can or @ appreciate time. provide more details need.

you can run migration add :complete order, i.e.

rails g migration add_complete_to_order 

then in generated migration file:

add_column :orders, :complete, :boolean, default: false 

then in order.rb can add method:

def complete!   update(complete: true) end 

which can call @ time in process when want mark order complete

you can use button_to create button. [http://apidock.com/rails/actionview/helpers/urlhelper/button_to ]

<%= button_to "mark complete", { action: "complete", id: @order.id } %> 

or instead of hash, can use full path, complete_order_path(@order) (check path running rake routes.

but need either add new route , action in orders controller. example:

resources :orders   post "complete", to: "orders#complete", on: :member end 

which should give url structure of orders/:order_id/complete in orderscontroller:

def complete   order = order.find(params[:order_id])   order.complete!   # handle response end 

but 1 example of how can that

if have collection of orders, need loop through each 1 , define button each order. example:

- @orders.each |order|  = button_to "#{order.name}: mark complete", complete_order_path(order) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -