Cliff_Cleet
Cliff_Cleet

Reputation: 211

Form url in Ruby on rails

In my ruby application there is a form in the cart page for checkout .

= form_for @order, url: update_cart_path, html: { id: 'update-cart', class: 'edit-cart'} do |order_form|


    %div{ data: { hook: 'inside_cart_form'}}
    %div{ data: { hook: 'cart_items' }, style: 'margin-bottom: 20px' }
    = render :partial => 'form', :locals => { :order_form => order_form }
    ----------
    ----------
    ----------
    .row
    .col-sm-4
    = button_tag class: 'btn btn-primary btn-block', id: 'checkout-link', name: 'checkout' do
    = Spree.t(:checkout)

Here, the form url is given as 'update_cart_path', But i cannot found a function named like this in the controller ...

I am newbie in ruby..

Please help me to solve this issue ...

config/routes.rb

xxxxx::Application.routes.draw do
  # We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
  mount Spree::Core::Engine, at: '/'
  mount MailPreview, at: 'mail_view' if Rails.env.development?

  Spree::Core::Engine.routes.draw do
    get  'measure' => 'home#measure'
    get  'about' => 'home#about'
    get  'sizes' => 'orders#sizes'
    get  'paypal' => 'paypal#express', as: :express_paypal
    get '/products/:id/:variant_name' => 'products#show', as: :product_variant_detail

    resources :variants, only: [] do
      get :carousel
      get :description
    end

    resources :orders do
      member do
        post 'increase', defaults: { format: 'json' }
        post 'decrease', defaults: { format: 'json' }
      end
      collection do
        put 'add_coupon_code'
      end
    end

    namespace :admin do
      resources :blog_entries, only: [] do
        resources :blog_entry_images, except: [:index, :show]
      end
    end
  end
end

Upvotes: 0

Views: 441

Answers (2)

user9595038
user9595038

Reputation:

If you want to customize spree behavior you have two options:

1) For example, if we have a controller file named:

test_controller.rb

then decorator file name would be:

test_controller_decorator.rb

So, if we have following controller from Spree:

\app\controllers\spree\products_controller.rb

we can create following decorator in our project:

\app\controllers\spree\products_controller_decorator.rb

Now, we add following code:

module Spree
  Spree::ProductsController.class_eval do

     # copy and paste existing actions here and customize

  end
end

2) Create the same file in the same directory and copy/paste from the source code and customize.

The file you are looking for is here: https://github.com/spree/spree/blob/master/frontend/config/routes.rb

Upvotes: 0

Anand
Anand

Reputation: 6531

Go to your console and run

rake routes

you will see all routes like this:

prefix      verb  URL        crontroller#action
update_cart patch /your/url  carts#update
            put   /your/url  carts#update

in this way you will get to know what is this url for and for which action and which controller. alternatively you can also check your config/routes.rb.

hope this will help you.

Upvotes: 1

Related Questions