Rails:不同控制器的形式 [英] Rails: form for different controller

查看:43
本文介绍了Rails:不同控制器的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有登陆页面的 rails 应用程序.在登陆页面上,用户可以注册该应用程序.对于登录,有一个带有额外控制器的额外视图.

I'm developing a rails app with a landingpage. On the landingpage, the user can sign up for the app. For login, there is an extra view with an extra controller.

看起来像这样:

views/landinpage/index.html --> sign up form
views/login/index.html --> login form

但我只想拥有一个控制器

but I only want to have one controller

controllers/login_controller --> create new user from sign up form & check login data

所以我必须在登陆页面视图和 login_controller 之间建立连接.

so I have to get a connection between the landingpage view and the login_controller.

这是我的尝试:

<%= form_for @login, :url => { :controller => "login_controller", :action => "create" }, :html => {:method => :post} do |f| %>

但它抛出一个路由错误:

but it throws a route error:

No route matches {:controller=>"login_controller", :action=>"create"}

我已经在routes.rb中定义了登录资源,但似乎问题出在其他地方?

I already defined login resources in routes.rb, but it seems that the problem is elsewhere?

resources :logins

有什么想法吗?

推荐答案

试试这个

class LoginsController < ApplicationController
   def new
     ...
   end

   def create
     ...
   end
  ...
 end

在你的 route.rb 文件中写入

in your route.rb file write

  match '/login/create' => 'logins#create', :as => :create_login
  or
  resources :logins

在你的控制台 - 写 - rake routes 并检查你的路由

in your console - write - rake routes and check your routes

然后

<%= form_for @login, :url => create_login_path(@login) do |f| %>

这篇关于Rails:不同控制器的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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