Ruby on rails 如何查看扩展名为.html.haml的文件的输出

Ruby on rails 如何查看扩展名为.html.haml的文件的输出,ruby-on-rails,ruby,haml,Ruby On Rails,Ruby,Haml,请帮助我,我正在处理一个rails项目,我创建了一个扩展名为.html.haml的视图文件,但是现在当我试图查看该文件的输出时,它给出了一个错误。是否有任何其他方法来查看此类扩展名的文件,我使用的是使用exyension.html.erb查看文件时使用的方式。我在控制器nd中创建了一个操作,该操作与routes.rb中的路径匹配。请帮助我,提前谢谢。 我的routes.rb文件是 PretAChef::Application.routes.draw do # mount FeatherCm

请帮助我,我正在处理一个rails项目,我创建了一个扩展名为.html.haml的视图文件,但是现在当我试图查看该文件的输出时,它给出了一个错误。是否有任何其他方法来查看此类扩展名的文件,我使用的是使用exyension.html.erb查看文件时使用的方式。我在控制器nd中创建了一个操作,该操作与routes.rb中的路径匹配。请帮助我,提前谢谢。 我的routes.rb文件是

PretAChef::Application.routes.draw do

  # mount FeatherCms::Engine => "/feathers"

  # get 'pages/:name' => 'feather_cms/pages#published', :as => 'feather_published_page'
  resources :messages, only: [:destroy, :show] do
    member do
      post :reply
      get :mark_read
    end
  end

  resources :bookings, only: [] do
    resources :messages, only: [:new, :create]
  end


    resources :chefs, :only => [:index, :show] do
        member do
      get :feedbacks
    end
  end
  resources :customers, :only => [] do
    member do
      get :feedbacks
    end
  end

  resources :ingredients, only: [:index]

  resources :cuisines, only: [:index]

  resources :home do
    collection do
      post :contact
    end
  end
  root :to => 'home#index'
  match 'contact_us' => 'home#contact_us', :as => :contact_us
    match 'mypop' => 'chefs#mypop', :as => :mypop

  devise_for :users, :controllers => {:registrations  => "users/registrations", :sessions => "users/sessions", :passwords => "users/passwords", :confirmations => "users/confirmations", :omniauth_callbacks => "users/omniauth_callbacks" }

  devise_scope :user do
    match "/chef/sign_up" => "users/registrations#new_chef", as: :chef_sign_up
    match "/chef/sign_in" => "users/sessions#new_chef", as: :chef_sign_in
    match "/users/sign_out" => "users/sessions#destroy", as: :sign_out
  end

  resource :profiles, :only => [:edit, :update] do
  end

  namespace :customer do
    resource :dashboards, only: [:show]
    resources :bookings, :only => [:create, :update, :edit, :destroy] do
      collection do
        get :booking_confirmation
        get :book_chef
      end
      member do
        # TODO: WTF: use destroy for cancelation
        post :rate
        post :comment
        get :feedback
        get :pay
        get :complete
        get :confirm
      end
    end
  end

  namespace :admin do
    resources :messages, only: [:index, :show] do
      collection do
        get :contact_us
        get :messages
      end
    end
    resources :cuisines, except: [:show]
    resources :bookings, only: [:index, :update, :edit, :destroy]


    resources :users, only: [:index, :update, :edit] do
      collection do
        get :active
        get :pending
      end
      resources :menus, except: [:index] do
        collection do
          post :preview
          get :destory_dish_image
        end
      end
      resources :availabilities, only: [:create, :destroy]
      resources :chef_messages, only: [:destroy, :show, :index, :new, :create] do
        member do
          post :reply
          get :mark_read
        end
      end

      namespace :chef do
        resources :bookings, only: [:edit, :update] do
          member do
            get :accept
            post :rate
            post :comment
            get :feedback
          end
        end
      end

    end

    resources :searches, only: [:index] do
      collection do
        get "user"
      end
    end
  end

  namespace :chef do
    resources :bookings, only: [:edit, :update] do
      member do
        get :accept
        post :rate
        post :comment
        get :feedback
      end
    end
    resource :dashboards, only: [:show]
    resources :menus, except: [:index] do
      collection do
        post :preview
        get :destory_dish_image
      end
    end
    resources :availabilities, only: [:create, :destroy]
  end

  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id))(.:format)'
end  
!!!
%html
  %head
    :css
      /* popup_box DIV-Styles*/
      #popup_box { 
          display:none; /* Hide the DIV */
          position:fixed;  
          _position:absolute; /* hack for internet explorer 6 */  
          height:300px;  
          width:600px;  
          background:#FFFFFF;  
          left: 300px;
          top: 150px;
          z-index:100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
          margin-left: 15px;  

          /* additional features, can be omitted */
          border:2px solid #ff0000;      
          padding:15px;  
          font-size:15px;  
          -moz-box-shadow: 0 0 5px #ff0000;
          -webkit-box-shadow: 0 0 5px #ff0000;
          box-shadow: 0 0 5px #ff0000;

      }

      #container {
          background: #d2d2d2; /*Sample*/
          width:100%;
          height:100%;
      }

      a{  
      cursor: pointer;  
      text-decoration:none;  
      } 

      /* This is for the positioning of the Close Link */
      #popupBoxClose {
          font-size:20px;  
          line-height:15px;  
          right:5px;  
          top:5px;  
          position:absolute;  
          color:#6fa5e2;  
          font-weight:500;      
      }
    %title Popup Box DIV
    %script{src: "http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js", type: "text/javascript"}
    :javascript
      $(document).ready( function() {

          // When site loaded, load the Popupbox First
          loadPopupBox();

          $('#popupBoxClose').click( function() {            
              unloadPopupBox();
          });

          $('#container').click( function() {
              unloadPopupBox();
          });

          function unloadPopupBox() {    // TO Unload the Popupbox
              $('#popup_box').fadeOut("slow");
              $("#container").css({ // this is just for style        
                  "opacity": "1"  
              }); 
          }    

          function loadPopupBox() {    // To Load the Popupbox
              $('#popup_box').fadeIn("slow");
              $("#container").css({ // this is just for style
                  "opacity": "0.3"  
              });         
          }        
      });
  %body
    #popup_box
      / OUR PopupBox DIV
      %h1 This IS A Cool PopUp
      %a#popupBoxClose Close
    #container
      / Main Page
      %h1 sample
我的视图文件是

PretAChef::Application.routes.draw do

  # mount FeatherCms::Engine => "/feathers"

  # get 'pages/:name' => 'feather_cms/pages#published', :as => 'feather_published_page'
  resources :messages, only: [:destroy, :show] do
    member do
      post :reply
      get :mark_read
    end
  end

  resources :bookings, only: [] do
    resources :messages, only: [:new, :create]
  end


    resources :chefs, :only => [:index, :show] do
        member do
      get :feedbacks
    end
  end
  resources :customers, :only => [] do
    member do
      get :feedbacks
    end
  end

  resources :ingredients, only: [:index]

  resources :cuisines, only: [:index]

  resources :home do
    collection do
      post :contact
    end
  end
  root :to => 'home#index'
  match 'contact_us' => 'home#contact_us', :as => :contact_us
    match 'mypop' => 'chefs#mypop', :as => :mypop

  devise_for :users, :controllers => {:registrations  => "users/registrations", :sessions => "users/sessions", :passwords => "users/passwords", :confirmations => "users/confirmations", :omniauth_callbacks => "users/omniauth_callbacks" }

  devise_scope :user do
    match "/chef/sign_up" => "users/registrations#new_chef", as: :chef_sign_up
    match "/chef/sign_in" => "users/sessions#new_chef", as: :chef_sign_in
    match "/users/sign_out" => "users/sessions#destroy", as: :sign_out
  end

  resource :profiles, :only => [:edit, :update] do
  end

  namespace :customer do
    resource :dashboards, only: [:show]
    resources :bookings, :only => [:create, :update, :edit, :destroy] do
      collection do
        get :booking_confirmation
        get :book_chef
      end
      member do
        # TODO: WTF: use destroy for cancelation
        post :rate
        post :comment
        get :feedback
        get :pay
        get :complete
        get :confirm
      end
    end
  end

  namespace :admin do
    resources :messages, only: [:index, :show] do
      collection do
        get :contact_us
        get :messages
      end
    end
    resources :cuisines, except: [:show]
    resources :bookings, only: [:index, :update, :edit, :destroy]


    resources :users, only: [:index, :update, :edit] do
      collection do
        get :active
        get :pending
      end
      resources :menus, except: [:index] do
        collection do
          post :preview
          get :destory_dish_image
        end
      end
      resources :availabilities, only: [:create, :destroy]
      resources :chef_messages, only: [:destroy, :show, :index, :new, :create] do
        member do
          post :reply
          get :mark_read
        end
      end

      namespace :chef do
        resources :bookings, only: [:edit, :update] do
          member do
            get :accept
            post :rate
            post :comment
            get :feedback
          end
        end
      end

    end

    resources :searches, only: [:index] do
      collection do
        get "user"
      end
    end
  end

  namespace :chef do
    resources :bookings, only: [:edit, :update] do
      member do
        get :accept
        post :rate
        post :comment
        get :feedback
      end
    end
    resource :dashboards, only: [:show]
    resources :menus, except: [:index] do
      collection do
        post :preview
        get :destory_dish_image
      end
    end
    resources :availabilities, only: [:create, :destroy]
  end

  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id))(.:format)'
end  
!!!
%html
  %head
    :css
      /* popup_box DIV-Styles*/
      #popup_box { 
          display:none; /* Hide the DIV */
          position:fixed;  
          _position:absolute; /* hack for internet explorer 6 */  
          height:300px;  
          width:600px;  
          background:#FFFFFF;  
          left: 300px;
          top: 150px;
          z-index:100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
          margin-left: 15px;  

          /* additional features, can be omitted */
          border:2px solid #ff0000;      
          padding:15px;  
          font-size:15px;  
          -moz-box-shadow: 0 0 5px #ff0000;
          -webkit-box-shadow: 0 0 5px #ff0000;
          box-shadow: 0 0 5px #ff0000;

      }

      #container {
          background: #d2d2d2; /*Sample*/
          width:100%;
          height:100%;
      }

      a{  
      cursor: pointer;  
      text-decoration:none;  
      } 

      /* This is for the positioning of the Close Link */
      #popupBoxClose {
          font-size:20px;  
          line-height:15px;  
          right:5px;  
          top:5px;  
          position:absolute;  
          color:#6fa5e2;  
          font-weight:500;      
      }
    %title Popup Box DIV
    %script{src: "http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js", type: "text/javascript"}
    :javascript
      $(document).ready( function() {

          // When site loaded, load the Popupbox First
          loadPopupBox();

          $('#popupBoxClose').click( function() {            
              unloadPopupBox();
          });

          $('#container').click( function() {
              unloadPopupBox();
          });

          function unloadPopupBox() {    // TO Unload the Popupbox
              $('#popup_box').fadeOut("slow");
              $("#container").css({ // this is just for style        
                  "opacity": "1"  
              }); 
          }    

          function loadPopupBox() {    // To Load the Popupbox
              $('#popup_box').fadeIn("slow");
              $("#container").css({ // this is just for style
                  "opacity": "0.3"  
              });         
          }        
      });
  %body
    #popup_box
      / OUR PopupBox DIV
      %h1 This IS A Cool PopUp
      %a#popupBoxClose Close
    #container
      / Main Page
      %h1 sample

我的操作是mypop in chefs controller。

看来您还没有为它安装gem。您只需将gem haml添加到gem文件中。运行包安装


完成了。

首先,您需要将所有css和脚本放在资产下,而不是放在模板本身上,其次,您可以稍微解释一下您的问题。我的意思是,你在调用什么动作,你如何呈现你的文件,它将执行哪个动作

@RajeshKolappakam问题是,我试图将它发送到我定义的那个动作,以显示我的haml文件bt,而不是该方法,它将发送到该控制器的某个其他方法,并显示其中的错误。请告诉我该怎么做。你能发布你的路线吗。rb文件是的,我正在编辑我的帖子。发布你的haml模板。我已经发布了这两个文件,请现在帮助。我已经安装了gem,实际上这个项目是由其他人完成的,现在它已经到我这里来进行一些修改,我已经将一个新文件从我这边添加到它的视图文件夹其他文件中还有一些扩展名相同的文件正在运行。我从来没有使用过扩展名为.haml的用户文件,我是rails的新手,总是使用扩展名为.html.erb的文件,请建议我怎么做?好的,我将把我所有的css放在我的资产中。其次,问题是我试图查看mypop.html.haml文件的输出,为此,我在chefs controller中创建了一个操作,并在我的routes.rb文件中匹配该路径,正如你在我的routes.rb文件bt中看到的那样,它显示了错误,没有显示任何o/p。问题是我试图将它发送到我定义的那个动作,以显示我的haml文件bt,而不是那个方法,它将发送到那个控制器的其他方法,并显示其中的错误。请告诉我该怎么做。你能具体一点,写下你的全部错误吗?其次,我在问,你是从哪个动作呈现这个模板的。您可以发布以下操作错误:ActiveRecord::StatementInvalid in ChefsControllershow SQLite3::SQLException:无此类列:true:选择用户。*其中users.id=0、role=1和confirmed\u at不为NULL且approve=true LIMIT 1 Rails.root:/users/sumitkalra1984/pretachef Application Trace | Framework Trace | Full Traceapp/controllers/chefs_controller.rb:27:'find_chef'请求参数:{id=>mypop}显示会话转储显示环境转储响应头:None@IshanSharma从您的错误中,我可以看到您的haml模板没有问题。问题在于您在chefs_控制器中的操作,或者更具体地说,在chefs_控制器的第27行中。你能发布那个动作吗