저는 프로그래밍이 처음이며 RoR을 처음 사용합니다.Splash 페이지 : 전자 메일 모음 (Rails 3.2)
스플래시 페이지에 간단한 이메일 수집 양식을 작성하려고하지만 브라우저에서 페이지를로드하려고 시도 할 때 예외가 발생합니다. 다음은 네 개의 관련 파일은 다음과 같습니다
emails_controller.rb
class EmailsController < ApplicationController
def new
render :layout => false
@email = Email.new
end
def show
email = Email.find(params[:id])
end
end
email.rb
class Email < ActiveRecord::Base
attr_accessible :email
email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
end
routes.rb
Splashtest::Application.routes.draw do
get "emails/new"
match 'splash', :to => 'emails#new'
end
는
정의되지 않은 메서드 NilClass에 대한`MODEL_NAME ': 클래스
나를 이해하는 데 도움이됩니다 14,new.html.erb 여기
<h1>Get notified when we launch:</h1>
<%= form_for(@email) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
내가 http://localhost:3000/splash를로드 할 때 내가 오류입니다 페이지를 보려고 시도 할 때 왜 오류가 발생합니까? 내 목표는 내 데이터베이스에 이메일 주소를 저장하는 것입니다. 더 많은 코드가 필요하다는 것을 이해합니다. 그러나 먼저이 오류를 지나치고 싶습니다.
나는 @을 놓쳤지만, 나는 그것이 무엇인지 알았다. render => false와 @email = Email.new를 렌더링과 교환해야했습니다. –