난 레일에 product
이라는 이름으로 스캐 폴딩 된 응용 프로그램을 만들었습니다. product_controller.rb 파일에는 다음이 포함되어 있습니다.ruby on rails 기본 도움말
class ProductsController < ApplicationController
def new
@product = Product.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @product }
end
end
def create
@product = Product.new(params[:product])
respond_to do |format|
if @product.save
flash[:notice] = 'Product was successfully created.'
format.html { redirect_to(@product) }
format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
이제 URL http://localhost:3000/products/create
가
을 주어 졌을 때, 제어 컨트롤러 클래스에 새로운 정의로 전송 한 후 인스턴스 변수 @product가 생성됩니다. 이 변이는 어디에서 흘러 나왔습니까? 여기 @product
<% form_for(@product) do |f| %> #all form elements declaration <% f.submit "Create" %> <%= end %>
컨트롤러 파일에서 초기화이 new.rhtml에 전달을 포함하는 new.rhtml 차례로 함수가 호출합니다. 그렇다면 form_for (@product)가 데이터를 가져 오는 위치는 어디입니까?
제출 버튼을 클릭 할 때 컨트롤러 파일에 함수를 만들기 위해 컨트롤이 어떻게 전송됩니까? 컨트롤러 파일에 조치가 지정되지 않습니다. @product 객체가 new.html 파일에서 수신되는 경우 redirect_to (@product)가 지정 않습니다 무엇을 만들 기능에
, ...
나는 매우 혼란의 기초에 대한 생각 ROR. 누군가 내가 이것을 분명히하도록 도와주세요. 큰 게시물을 작성해 주신 것을 용서해주십시오. 이 단일 코드에서 많은 의문점을 가지고 있습니다.
일부 태그를 추가하면이 질문이 더 유용 해지고 사람들이 더 쉽게 찾을 수 있습니다. 아마도 "스캐 폴딩 (scaffolding)", "라우팅 (routing)", "REST"등이 될 수 있습니다. "레일스에서 새로운 객체를 만드는 컨트롤러와 폼은 어떻게 작동합니까?" – Andrew