Ruby on Rails中注册的多个用户视图

时间:2017-03-11 12:34:56

标签: ruby-on-rails ruby

我想创建两个不同的注册页面。所以从我的家庭视图我创建了这些按钮:

<% if not logged_in? %>
  <%= link_to "I'm a Hero", signup_path, class: "btn btn-lg btn-primary" %>
  <%= link_to "I'm a villain", villain_path, class: "btn btn-lg btn-primary" %>

<% end %>

现在这条路线对于&#34;我是英雄&#34;显然是这样的。按钮:

  get 'signup'  => 'users#new'

我可以在视图中呈现一个很好的注册表单 - &gt;用户 - &gt; new.html.erb。我以为我可以为我的#34;我是一个恶棍&#34;做同样的事情。按钮。

首先,我想创建一个新的文件视图 - &gt;用户 - &gt; villain.html.erb。然后我想创建一个这样的路线:

  get 'villain'  => 'users#villain'

如果我现在点击我的&#34;我是一个恶棍&#34;按钮,基本没什么事。至于localhost:3000 / villain,我被重定向到localhost:3000。

我错过了什么?

这是点击&#34;我是恶棍&#34;

时的服务器日志
Started GET "/villain" for 130.75.71.234 at 2017-03-11 14:07:00 +0000
Cannot render console from 130.75.71.234! Allowed networks: 127.0.0.1, ::1,     127.0.0.0/127.255.255.255
Processing by UsersController#villain as HTML
User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" IS NULL  LIMIT 1
Redirected to https://ruby-project.c9users.io/
Completed 302 Found in 601ms (ActiveRecord: 1.5ms)


Started GET "/" for 130.75.71.234 at 2017-03-11 14:07:01 +0000
Cannot render console from 130.75.71.234! Allowed networks: 127.0.0.1, ::1,   127.0.0.0/127.255.255.255
Processing by StaticPagesController#home as HTML
User Load (0.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" IS NULL   LIMIT 1
CACHE (0.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Rendered static_pages/home.html.erb within layouts/application (4.6ms)
Rendered layouts/_shim.html.erb (0.5ms)
CACHE (0.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Rendered layouts/_header.html.erb (2.0ms)
Rendered layouts/_footer.html.erb (0.8ms)
Completed 200 OK in 386ms (Views: 381.7ms | ActiveRecord: 0.5ms)

1 个答案:

答案 0 :(得分:0)

您需要在控制器中定义“恶棍”动作。您可能已经定义了“新”操作,因为您是通过生成器创建的。这可能就是为什么“新”行动确实起作用而不是“反派”行动的原因。