레일즈 form_for 헬퍼를 사용하는 동안 라우팅 오류가 발생합니다. 나는 주변을 검색하고 this question을 보았지만, pluralize로 "static_event"에 대한 복수형은 "static_events"이므로 손실이 발생했습니다. 어떤 도움도 감사 할 것입니다. 여기에 세부 사항은 ....입니다레일을 사용하는 중에 "_path"로 정의되지 않은 메서드 form_for
ActionView::Template::Error (undefined method `static_events_path' for #<#<Class:0x007f9fcc48a918>:0x007f9fcc46fa78>):
내 모델 :
class StaticEvent < ActiveRecord::Base
attr_accessible :content, :title, :discount, :location, :day_of_week, :start_time
내 컨트롤러 :
class StaticEventsController < ApplicationController
before_filter :authenticate, :only => [:create, :destroy]
before_filter :authorized_user, :only => [:destroy]
def new
@title = "Share An Event"
@static_event = StaticEvent.new
end
def create
@static_event = current_user.static_events.build(params[:event])
if @static_event.save
flash[:success] = "Event Shared"
redirect_to @static_event #this was the old version
else
render :new
end
end
경로 :
match '/static-events/new', :to => 'static_events#new'
match '/static-events/', :to => 'static_events#index'
match '/static-events/:id', :to => 'static_events#show'
뷰
<%= form_for (@static_event) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<%= text_field "static_event", "title", "size" => 48 %>
<%= time_select "static_event", "start_time", {:ampm => true, :minute_step => 15} %>
<%= text_area "static_event", "content", "cols" => 42, "rows" => 5 %>
<%= text_field "static_event", "discount", "size" => 48 %>
<%= text_field "static_event", "location", "size" => 48 %>
<%= text_field "static_event", "day_of_week", "size" => 48 %>
<input name="" type="submit" class="button" value="share on chalkboard" />
<% end %>
위대한, 이걸 업데이 트했습니다. 감사 파비 오! – Alekx
레일 4에서 http 메서드를 'via'로 지정해야합니다 – courtsimas
중첩 된 경로의 경우 한 쌍의 값을 전달해야하므로 'form_for ([@ static_event, @ sub_event])' –