Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active March 6, 2024 17:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save maxivak/720aed6f4f4e3619eb3c54b1f7797b98 to your computer and use it in GitHub Desktop.
Save maxivak/720aed6f4f4e3619eb3c54b1f7797b98 to your computer and use it in GitHub Desktop.
Building URLs for simple_form - all examples. Rails

Namespace

Namespace and simple_form

  • namespace 'admin'
= simple_form_for([:admin,@item], html: { class: 'form-horizontal' }) do |f|
    

Namespace and simple_form and member action

  • routes:
scope '/admin' do
    scope module: 'admin', as: 'admin' do
      resources :products do
        member do
          get :edit_translations
          post :update_translations
        end
      end    
    end
end    
  • controller
class Admin::ProductsController < Admin::MyAdminBaseController

  def edit_translations
    @item = Product.find(params[:id])
  end

end

  • form for products#edit_translations
= simple_form_for([:admin,@item], 
    :url => url_for(:action => 'update_translations', :controller => 'products'),
    :method => 'post', html: { class: 'form-horizontal' }) do |f|
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment