2012-09-19 4 views
0

머리를 감당할 수 없어서 ... 누군가이 코드로 어떤 일이 벌어지고 있는지 말해 줄 수 있습니까?레일에서 빈 폼 데이터 문제가 발생했습니다.

기본적으로 양식에서 데이터를 가져 오려고합니다. 나는 수 백번 컨트롤러, 모델, 뷰를 확인했지만 일을 할 기회가 없었다. 디버그 @ 프로그램 결과는 항상 모든 필드를 채우지 만 이러한 이벤트와 같습니다 : BLANK.

컨트롤러 :

class ProgramsController < ApplicationController 
    def index 
    @program = Program.all 
    end 

    def show 
    @program = Program.find(params[:id]) 
    end 

    def create 
    @program = Program.new 

    if @program.save 
     redirect_to 'index' 
    else 
     render 'new' 
    end 
    end 

    def new 
    @program = Program.new 
    end 


    def edit 
    end 

    def destroy 
    end 
end 

모델 :

class Program < ActiveRecord::Base 
    attr_accessible :active, :content, :title 

    validates :title, presence: true 
    validates :content, presence: true 

end 

보기 :

<html> 
<head> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
    <title>Program Adding</title> 
</head> 
<body> 

    <% if @program.errors.any? %> 
    <% @program.errors.full_messages.each do |msg| %> 
    <%= msg %> 
    <% end %> 
    <% end %> 

    <%= form_for(@program) do |p|%> 
    <%= p.label :title%><br /> 
    <%= p.text_field :title %><br /> 

    <%= p.label :content%><br /> 
    <%= p.text_area :content %><br /> 

    <%= p.label :active%><br /> 
    <%= p.text_field :active %><br /> 

    <%= p.submit %> 

    <% end %> 

    <%= debug @program %> 

</body> 
</html> 
--- !ruby/object:Program attributes: 
id:  
title:  
content: 
active:  
created_at:  
updated_at: 

여기에 코드입니다고맙습니다.

답변

2

작성 작업에 양식 값을 전달하지 않는 것 같습니다.

@program = Program.new 

모든 당신이 표준 편안한 라우팅을 사용하는 가정입니다

@program = Program.new(params[:program]) 

이와 그 라인을 교체하십시오.

건배.

+0

대단히 감사합니다! 당신은 내 고통을 완화! :) – scaryguy

+0

기꺼이 도와 드리겠습니다. D –

관련 문제