Usage Rails 3.0 beta 3 without ActiveRecord ORM
Just installed Rails 3.0 beta 3 in Windows 7. And started playing with some easy examples
class SignupController < ApplicationController
def index
@user = User.new(params[:user])
if method.post? and @user.save
redirect_to :root
end
end
end
class User
def initialize(params = {})
@email = params[:email]
@passw = params[:password]
end
def save
end
end
<div align="center">
<% form_for :user do |form| %>
<%= form.label :email %>
<%= form.text_field :email %><br />
<%= form.label :password %>
<%= form.text_开发者_高级运维field :password %><br />
<%= form.submit :Register! %>
<% end %>
</div>
When I go to /signup I'm getting this error
NoMethodError in SignupController#index
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[]
Is there a problem with constructor or what's wrong?Please, need your help! I just won't use ActiveRecord or any other ORM.
You need another action to handle the post, possibly it is called create
. This is how I would revise your controller:
def index
@user = User.new
end
def create
@user = User.new(params[:user])
if method.post? and @user.save
redirect_to :root
end
end
The error possibly because when the index
is displayed, params
variable had no content.
精彩评论