route.rb 的问题 [英] Problems with routes.rb

查看:40
本文介绍了route.rb 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 routes.rb 有问题

I have a problem with routes.rb

在我的 Web 应用程序中,我有两个带有登录表单的页面

In my web application i have two pages with the login form

"/home/index" 和 "/users/index"

"/home/index" and "/users/index"

这是我的路由文件

  controller :home do
    get     'login'   => :index
    post    'login'   => :create
  end

  controller :users do
    get     'login'   => :index
    post    'login'   => :post_login
  end

  get "home/index"

  get "home/create"

  get "home/show"

  get "private/index"

  get "users/index"

  get "users/get_login"

  get "users/post_login"

  resources :users do
    collection do
      get  'get_login'
      post 'post_login'
    end
  end

问题是,如果我使用home/index"登录,它会执行家庭控制器的正确操作create",而如果我登录users/index"页面,它会再次执行create"post_login",为什么?

the problem is that if i use login with my "home/index" it executes the right action "create" of the home controller, while if i login in "users/index" page it executes again the "create" instead of "post_login", why?

我在/home/index"和/users/index"中用于表单的代码是相同的...

The code i used for my form in "/home/index" and "/users/index" is the same...

这是简单的形式

<%= form_tag do %>

    <table>
        <tr>
            <td>
                <%= text_field_tag :name, params[:name] %>
            </td>
        </tr>
        <tr>            
            <td>
                <%= password_field_tag :password, params[:password] %>
            </td>
        </tr>
        <tr>
            <td>
                <%= submit_tag "Login" %>           
            </td>
        </tr>
<% end %>
        <tr>            
            <td>
                <%= link_to 'Registrazione', users_index_url %>             
            </td>
        </tr>

    </table>

用户控制器代码:

class UsersController < ApplicationController


      def index

      end  

      def post_login
        redirect_to "http://www.google.it"
      end

    end

推荐答案

我会有用户,只是作为资源:

I would have users, only as resources:

 controller :home do
    get     'login'   => :index
    post    'login'   => :create
  end

  get "/users" => 'users#index'
  post "/users" => 'users#post_login'


  get "home/index"

  get "home/create"

  get "home/show"

  get "private/index"

在唯一的数组中,只需添加您正在使用的操作...

In the only array, just add the actions that u are using...

这篇关于route.rb 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆