jquery - Rails, How to mark an order as completed -


i need way apply method made order select. or find way mark complete.

this tried far. don't mind trying new. have these orders display in view so:

.col-md-12   .admindash     %h1 admin dashboard     .text-norm       welcome admin dashboard here can see incoming , outgoing orders.  .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     = link_to "data control", rails_admin_path, :class => 'btn-danger btn'     %p     = link_to "back dashboard", :back, :class => 'btn-danger btn' 

i want add button page can mark orders complete maybe make table orders , button says mark complete.

so ran migration add boolean class of complete.

class addcompletetoorder < activerecord::migration   def change     add_column :orders, :complete, :boolean, default: false   end end 

then in orders controller made:

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   mount railsadmin::engine => '/admin', as: 'rails_admin'   'home/index'   root 'home#index'   #pages   '/why' => 'pages#why'   '/trak' => 'pages#trak'   '/contact' => 'pages#contact'   '/mydms' => 'pages#mydms'   '/air' => 'pages#air'   '/ocean' => 'pages#ocean'   '/road' => 'pages#road'   '/courier' => 'pages#courier'   'fulfilment' => 'pages#fulfilment'   'express' => 'pages#express'    resources :dashboard   'dadmin' => 'dashboard#dadmin'   'myorders' => 'dashboard#myorders'   'label' => 'dashboard#label'   resources "contacts", only: [:new, :create]    devise_for :users   :user     'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'     put 'users' => 'devise/registrations#update', :as => 'user_registration'   end    resources "orders"   "confirm" => "confirmations#show"   'dconfirmation' => 'orders#confirmation' end 

so need way update specific order. list orders @order.id select order user method. don't know i'm doing i'm new rails. please help. need indicate order completed.

i don't mind how mark order complete, needs remember if page reloaded , site use jquery. there method can through?

there few options, here's 1 keeps controller restful.

first - instead of boolean, use datetime.

class addcompletetoorder < activerecord::migration   def change     add_column :orders, :completed_at, :datetime   end end 

in controller, use update method, have respond_to js

respond_to |format|   format.html { redirect_to [:admin, @order] }   format.js { render :update } end 

make update.js.erb (or haml) view. looks you're using haml.

- order_list_item = render :partial => 'admin/orders/order', :locals => { :order => @order } $("##{dom_id(order)}").replacewith('#{j(order_list_item)}') 

you can reuse order partial.

in order partial, add button or link. think use button_to instead.

= link_to "completed", admin_order_path(order, 'order[completed]' => true), :remote => true, :method => :put 

and remember add dom_id _order.html.haml partial. haml gives convenient way that.

move it's own partial, instead of

- order in @order 

you have

# /admin/orders/_order.html.haml  %div[order]   ... other order code earlier loop 

and call so

= render @orders  # change instance variable name "@orders" match rails conventions 

in model, handle completed , completed=

class order < activerecord::base    def completed     !completed_at.nil?   end    def completed=(state=false)     completed_at = time.now if state   end  end 

check developer tools (in chrome or safari) response output if don't see page update @ first. can see errors way in response body.


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 -