रेल मैं एक (मुझे लगता है कि) रूटिंग त्रुटि में चल रहा हूँ, जबकि सहायक form_for रेल का उपयोग कर का उपयोग करते समय। मैं चारों ओर खोज कर रहा हूं और this question पर देखा है, लेकिन बहुवचन के साथ "static_event" के लिए बहुवचन "static_events" है इसलिए मुझे नुकसान हुआ है। किसी भी मदद पर कब्जा कर लिया जाएगा। यहाँ विवरण .... हैंअपरिभाषित विधि 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 %>
ग्रेट तय की है, मैंने इसे अपडेट किया है। धन्यवाद Fábio! – Alekx
रेल 4 में, आपको http विधि के साथ-साथ – courtsimas
के साथ निर्दिष्ट करने की आवश्यकता होगी, एक पक्ष के रूप में, नेस्टेड मार्गों के लिए आपको मूल्यों की एक जोड़ी पारित करनी होगी ताकि 'form_for ([@ static_event, @ sub_event]) ' –