English 中文(简体)
2. 努力扎根,设计/拥有测绘错误的道路上的新结果
原标题:Trying to set root to devise/sessions#new results in routes mapping error

回答一个问题:

我的要求如下:

  1. 如果用户访问我的申请,那么,我寄望的根基就落到宣传页和纸张上;签名表格。 通过检查子库的存在来实现这一点。

  2. 如果用户没有入住,并试图在测试时访问其账户。 我的赞同。 -aka-设计/会议

  3. 如果用户在(发展中国家)和访问测试中被贴上标签。 申请的根基是应用仪表板。

Here is what I am trying to use in my routes.rb

constraints(Subdomain) do
  authenticated do
    root :to =>  dashboard#index 
  end
  root :to =>  devise/sessions#new 
end
root :to =>  promo_pages#index 

现在我有以下内容,你将指出,设计范围没有包括在内。

constraints(Subdomain) do
  authenticated do
    root :to =>  dashboard#index 
  end
end
root :to =>  promo_pages#index 

My problem with the latter is that when a user who is not logged in first visits test.myapp.com they are redirected to test.myapp.com/users/sign_in and an error message is displayed saying "You need to sign in or sign up before continuing." This is because I am enforcing a logon requirement for the dashboard pages.

However I don t want the user to get an error message the first time they visit the page, as it is ugly and makes it look like they have done something wrong when they have not.

My expectation is that if the user is not logged in then they will be directed straight to the logon page and not get an error notification. But when I use my amended version the following happens, I can visit myapp.com just fine and it is routed to the promo pages but if I try to visit test.myapp.com I get the following message in the browser

**Unknown action**
Could not find devise mapping for path "/". Maybe you forgot to wrap your route inside the scope block? For example: devise_scope :user do match "/some/route" => "some_devise_controller" end 

请告诉我正在做什么错误(如果有的话),因为我正在试图理解什么。

Ps: I have found similar errors in stackoverflow and various googling but the solutions just don t seem to work for me. I expect that the solution to the problem lies in the error message that I have included above, but I can t figure out how to apply it.

Finally here is the log entry version of the error above, it is in an easier to read form.

Started GET "/" for 127.0.0.1 at 2012-01-15 21:44:42 +0000
  Processing by Devise::SessionsController#new as HTML
[Devise] Could not find devise mapping for path "/".
Maybe you forgot to wrap your route inside the scope block? For example:

    devise_scope :user do
      match "/some/route" => "some_devise_controller"
    end
Completed 404 Not Found in 1ms

AbstractController::ActionNotFound (Could not find devise mapping for path "/".
Maybe you forgot to wrap your route inside the scope block? For example:

    devise_scope :user do
      match "/some/route" => "some_devise_controller"
    end
):

All help is appreciated, and additional details can be provided.

阅读


<>Update>

I have just noticed that the authenticated check does not appear to be working. If it was working correctly then when using the second batch of working config, the logged in user visiting test.myapp.com would always be directed to the promo_pages, whereas at the moment he is able to access the dashboard..

I found the devise authenticated method here https://github.com/plataformatec/devise/pull/1147

最佳回答

我已经这样做了。

奥基首先,我之所以忘记了设计错误,是因为我需要在“为:用户”栏目中说明设计的内容。

Secondly, The authenticated check was not working because I failed to include a scope as I was under the mistaken impression it was not necessary.

Here is the finalised code, note that in rails routing the priority is based on order of creation, first created is highest priority. Thus in this case the promo_pages controller is only considered root if nothing else was previously specified.

constraints(Subdomain) do
  authenticated :user do
    root :to =>  dashboard#index 
  end

  unauthenticated :user do
    root :to =>  devise/sessions#new 
  end
end
root :to =>  promo_pages#index 
问题回答

在无限制的情况下,这会造成无法为道路“/”错误绘制地图。 这一简单增补固定了。

devise_scope :user do 
    authenticated :user do
      root :to =>  dashboard#index 
    end
    unauthenticated :user do
      root :to =>  devise/sessions#new 
    end
    root :to =>  dashboard#index 
end




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签