2011-01-11 11 views
2

내 루비 버전은 1.9.1입니다. 이것은 루비의 첫 번째 프로젝트입니다. 나는 개발을 시도하고 있습니다. 내가 몇 가지 정보를 입력하고 레코드를 저장하려고하면정의되지 않은 지역 변수 또는 메소드`request '

내가 오류 "나가서 설명하자면 NameError (정의되지 않은 지역 변수 또는 메소드 request' for #<User:0x3ab7220>): app/models/user.rb:36:in 로그인 '`가입에 : 7 응용 프로그램/컨트롤러/user_controller.rb'를"얻고있다. 다음은 컨트롤러 클래스

class UserController < ApplicationController 
    def signup 
    if request.post? and params[:user] 
     @user = User.new(params[:user]) 
     if @user.save 
     session[:user] = @user 
     flash[:notice] = "User #(@user.login) created !" 
     redirect_to :action =>"home" 
     else 
     flash[:error]="Signup unsuccessful" 
     @user.clear_password! 
     end 
    end 
    end 

    def home 
    @title = "Bookshelf - User Home" 
    end 

내 signup.html이다

<div id="signup_content"> 
<span class="title">Sign-up for a BookShelf account...</span> 
<% form_for :user, @user, :url => {:action => "signup" } do |f| %> 
    <%= error_messages_for 'user' %><br/> 

    <div class="signup_field"> 
     <label for="user_login">Login:</label> 
     <%= f.text_field :login %><br/> 
     </div> 

    <div class="signup_field"> 
     <label for="user_first_name">First Name:</label> 
     <%= f.text_field :first_name %><br/> 
    </div> 

    <div class="signup_field"> 
     <label for="user_password_confirmation">Password Confirmation:</label> 
     <%= f.password_field :password_confirmation %> 
    </div> 

    <%= submit_tag "Signup" %> 
<% end %> 

덧글이 지적한 것처럼

application.html

<html> 
    <head> 
    <title><%= @title %></title> 
    <%= stylesheet_link_tag "style" %> 
    <%= javascript_include_tag :defaults %> 
    </head> 
    <body> 
    <div id="header"> 
     <div id ="logo_image"> 
      <%= link_to image_tag('main_logo.png'), 
      :controller=>'home', :action=>'index' %> 
     </div> 

     <% if !session[:user] %> 
      <%= render :partial=>"user/signin" %> 
     <% else %> 
      <div id ="user_menu"><%= link_to 'Logout',:controller=>'user',:action=>'logout'%> 
      </div> 
     <% end %> 
     <div style="clear: both;height:0px;"></div> 
    </div>   
    <%= render :partial=> "shared/sidebar" %> 
    <div id="Content"> 
     <% if flash[:notice] -%> 
     <div id="notice"><%= flash[:notice] %></div> 
     <% end -%> 
     <% if flash[:error] -%> 
     <div id="error"><%= flash[:error] %></div> 
     <% end -%> 
     <!-- <%= yield %> uncommenting solved the double rendering problem-->      
    </div> 
    </body> 
</html> 
+0

정확한 오류 메시지를 알려주십시오 ... – Kunday

+0

오류는'user.rb' 줄에 있습니다 36.'user.rb'의 소스를 게시하십시오. – rfunduk

답변

2

, 당신의 오류가 user.rb입니다. 컨트롤러의 request 메소드에 액세스하려하고 있지만 그 시점에서 사용자가 User 클래스에 있기 때문에 그렇게 할 수 없습니다. 일반적으로 모델 레이어 (이 경우 User)는 다른 레이어 (컨트롤러 및 뷰 레이어)에 대해 알지 않아야합니다. 컨트롤러는 요청 및 응답과 관련된 사항을 처리하기위한 것입니다. MVC in Rails 또는 MVC in general을 읽어 볼 수 있습니다.

관련 문제