【发布时间】:2015-01-27 16:35:21
【问题描述】:
我有一个我想从注册控制器和表单创建的帐户模型。
index.html.erb
<div id="registration">
<%= form_for(@account) do |f| %>
<% if @account.errors.any? %>
register_controller.rb
class RegisterController < ApplicationController
def index
@account = Account.new
end
def create
@account = Account.new(parames[:account])
end
end
end
end
routes.rb
Rails.application.routes.draw do
get 'register/index'
get 'register/create'
我当前的问题是来自 form_for() 方法的 # 的未定义方法 `accounts_path'
我是不是因为类名而把事情搞混了?
【问题讨论】:
-
默认情况下,
form_for将尝试“猜测”提交表单的 URL。在你的情况下,你不希望表单提交给accounts_path,而是提交给form_for @account, url: registers_path(如果你在你的routes.rb中定义resources :register,否则我需要查看你的路由配置)
标签: ruby-on-rails ruby model controller