तो मैं त्रुटि मिलती रहती है:कोई मार्ग मेल ... रेल इंजन
No route matches {:action=>"create", :controller=>"xaaron/api_keys"}
कौन सा परीक्षण में फेंक दिया जाता है:
it "should not create an api key for those not logged in" do
post :create
expect(response).to redirect_to xaaron.login_path
end
जब मैं spec/dummy
के पास जाकर rake routes
चलाने कमांड मैं देखता हूं:
api_keys GET /api_keys(.:format) xaaron/api_keys#index
POST /api_keys(.:format) xaaron/api_keys#create
new_api_key GET /api_keys/new(.:format) xaaron/api_keys#new
edit_api_key GET /api_keys/:id/edit(.:format) xaaron/api_keys#edit
api_key GET /api_keys/:id(.:format) xaaron/api_keys#show
PATCH /api_keys/:id(.:format) xaaron/api_keys#update
PUT /api_keys/:id(.:format) xaaron/api_keys#update
DELETE /api_keys/:id(.:format) xaaron/api_keys#destroy
जो दिखाता है कि हाँ यह मार्ग मौजूद है। इस इंजन के लिए मेरी मार्ग फ़ाइल इस तरह दिखती है:
Xaaron::Engine.routes.draw do
get 'login' => 'sessions#new', :as => 'login'
get 'logout' => 'sessions#destroy', :as => 'logout'
get 'signup' => 'users#new', :as => 'signup'
get 'permission_denied' => 'error#denied', :as => 'permission_denied'
get 'record_not_found' => 'error#error', :as => 'record_not_found'
get 'password_reset' => 'password_resets#edit', :as => 'rest_user_password'
resource :error, controller: 'error'
resources :users
resources :api_keys
resources :sessions
resources :roles
resources :password_resets
end
मुझे क्या याद आ रही है?
अद्यतन
आप में से जो उत्सुक के लिए मैं कैसे इन मार्गों हो रही है, अपने डमी एप्लिकेशन के मार्गों फ़ाइल की स्थापना की है, क्योंकि (डिफ़ॉल्ट रूप से) जैसे:
Rails.application.routes.draw do
mount Xaaron::Engine => "/xaaron"
end
अद्यतन द्वितीय
मैं this api docs on how routing is done in engines पढ रहा हूं और मैं जिस तरह से मैं यह सही है किया है विश्वास करते हैं, कैसे कभी नियंत्रक इस तरह के रूप में परिभाषित किया जाता है:
module Xaaron
class ApiKeysController < ActionController::Base
before_action :authenticate_user!
def index
@api_key = Xaaron::ApiKey.where(:user_id => current_user.id)
end
def create
@api_key = Xaaron::ApiKey.new(:user_id => current_user.id, :api_key => SecureRandom.hex(16))
create_api_key(@api_key)
end
def destroy
Xaaron::ApiKey.find(params[:id]).destroy
flash[:notice] = 'Api Key has been deleted.'
redirect_to xarron.api_keys_path
end
end
end
अद्यतन के लिए धन्यवाद। मैं 'माउंट' पर थोड़ा सा शोध करूंगा। 'Api_keys' नियंत्रक कैसे परिभाषित किया गया है? क्या यह मॉड्यूल 'xaaron' के भीतर है? कृपया कुछ विशिष्ट विवरण/कोड साझा करें। –
@KirtiThorat उचित अपडेट किए गए हैं। जैसा कि मैंने कहा है कि मैं भी पढ़ रहा हूं: http://api.rubyonrails.org/classes/Rails/Engine.html बेहतर ढंग से समझने के लिए कि इंजन विशेष रूप से इंजनों में कैसे काम करते हैं। और मेरा मानना है कि मैंने यह सही तरीके से किया है - हालांकि मुझे कुछ आसान याद आना चाहिए। – user3379926