Jump to content

The ultimate community for Ruby on Rails developers.


Photo

How to manage the path to a template

wice_grid

  • Please log in to reply
4 replies to this topic

#1 dailammoc

dailammoc

    Dispatcher

  • Members
  • 37 posts
  • Location/

Posted 02 April 2014 - 10:01 AM

In my view directory I have two subdirectory for example: a and b. In a I have several files(new, index, edit, show). b only has index file. Now I set "index" in a as root and I can link directory to "new" by add this path in a button like this:

= link_to "new", url_for(new_b_path), class: "btn btn-white btn-sm"

(There is no typo here) The problem is, I cannot link to other path like edit_b_path ore show_b_path and I don't know why "new" can and others cannot. I use wice_grid plugin in my project.



#2 Ohm

Ohm

    Driver

  • Moderators
  • 398 posts
  • LocationCopenhagen

Posted 02 April 2014 - 10:43 AM

How are your routes specified?

 

The link_to helper doesn't need the url, it can work with the path, that is the following should work:

= link_to "new", new_b_path, class: "btn btn-white btn-sm"

if the new_b_path is valid.


Blog: http://ohm.sh | Twitter: @madsohm

#3 dailammoc

dailammoc

    Dispatcher

  • Members
  • 37 posts
  • Location/

Posted 02 April 2014 - 10:50 AM

Yes, your suggestion code worked correctly, my routes here:

SptHunter::Application.routes.draw do
  post "versions/:id/revert" => "versions#revert", :as => "revert_version"
  devise_for :admin_users
  resources :flights

  mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
  resources :dashboard, only: [:index]
  root to: 'master/hotels#index'
  resources :reservations do
    collection do
      get 'callcenter'
    end
  end

  concern :importable do
    collection do
      post :import
    end
  end

  #resources :products do
  #  collection { post :import }
  #end
  # マスタ
  namespace :master do
    # マスタ(商品)
    resources :hotels, concerns: [:importable]
    resources :flights, concerns: [:importable]
    resources :options, concerns: [:importable]
    resources :events, concerns: [:importable]
    resources :products, concerns: [:importable]
    resources :hotel_room_stocks, concerns: [:importable]

    # マスタ(取引先)
    resources :agencies, concerns: [:importable]
    resources :companies, concerns: [:importable]
    resources :clients, concerns: [:importable]

    # マスタ(設定)
    resources :product_categories, concerns: [:importable]
    resources :delivery_categories, concerns: [:importable]
    resources :airports, concerns: [:importable]
    resources :areas, concerns: [:importable]
    resources :prefectures, concerns: [:importable]
    resources :hotel_rooms, concerns: [:importable]

    # マスタ(社内)
    resources :admin_users, concerns: [:importable]
    resources :admin_news, concerns: [:importable]

  end
end

and in view I have directories: master/hotels(index) and cruds(index,new,show,form,edit). I can access new by:

= link_to "new", new_master_hotels_path, class: "btn btn-white btn-sm"

but

= link_to "new", show_master_hotels_path, class: "btn btn-white btn-sm"

cannot. I don't know why...



#4 Ohm

Ohm

    Driver

  • Moderators
  • 398 posts
  • LocationCopenhagen

Posted 02 April 2014 - 10:53 AM

Ahh, thats because the show path is special.

 

The show path is just the path without the method, but with an object send to it. Say you have a master hotel object in @hotel, then the show link would be:

= link_to "show", master_hotel_path(@hotel), class: "btn btn-white btn-sm"

Blog: http://ohm.sh | Twitter: @madsohm

#5 dailammoc

dailammoc

    Dispatcher

  • Members
  • 37 posts
  • Location/

Posted 02 April 2014 - 11:00 AM

 

Ahh, thats because the show path is special.

 

The show path is just the path without the method, but with an object send to it. Say you have a master hotel object in @hotel, then the show link would be:

= link_to "show", master_hotel_path(@hotel), class: "btn btn-white btn-sm"

my goal exactly is :

= link_to "button name", "path to show.html.haml form in cruds directory", class: "btn btn-white btn-sm"

hope it clear enough. I try your code and it still didn't work







Also tagged with one or more of these keywords: wice_grid

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users