estoy corriendo en un (creo) error de encaminamiento durante el uso de los rieles form_for ayudante. He estado buscando alrededor y miraba this question, pero el plural de "static_event" con pluralizar es "static_events" así que estoy en una pérdida. Cualquier ayuda sería apreciada. Aquí están los detalles ....método Indefinido con "_PATH" durante el uso de los carriles form_for
ActionView::Template::Error (undefined method `static_events_path' for #<#<Class:0x007f9fcc48a918>:0x007f9fcc46fa78>):
Mi Modelo:
class StaticEvent < ActiveRecord::Base
attr_accessible :content, :title, :discount, :location, :day_of_week, :start_time
Mi controlador:
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
La ruta:
match '/static-events/new', :to => 'static_events#new'
match '/static-events/', :to => 'static_events#index'
match '/static-events/:id', :to => 'static_events#show'
La vista
<%= 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 %>
Genial, lo he actualizado a esto. Gracias Fábio! – Alekx
En rieles 4, deberá especificar también el método http con 'via' – courtsimas
Como aspecto secundario, para las rutas anidadas deberá pasar un par de valores para' form_for ([@ static_event, @ sub_event]) ' –