路径错误:未定义的局部变量或方法`events_path'

时间:2014-06-16 06:42:27

标签: ruby events ruby-on-rails-4 routing fullcalendar

在rails 4.0.2中,我尝试实现日历功能以及事件。 我从https://github.com/vinsol/fullcalendar-rails-engine提到了。 但我正面临一些像

这样的路线问题
undefined local variable or method `events_path' for #<#<Class:0x9b8fed0>:0xb5e2e9a0>

在我添加的routes.rb文件中,

root 'welcome#index'
mount FullcalendarEngine::Engine => "/fullcalendar_engine"

生成的路线是,

$ rake routes
         Prefix Verb URI Pattern          Controller#Action
           root GET /                    welcome#index
fullcalendar_engine     /fullcalendar_engine FullcalendarEngine::Engine

Routes for FullcalendarEngine::Engine:
         root GET    /                            fullcalendar_engine/events#index
get_events_events GET    /events/get_events(.:format) fullcalendar_engine/events#get_events
   move_event POST   /events/:id/move(.:format)   fullcalendar_engine/events#move
 resize_event POST   /events/:id/resize(.:format) fullcalendar_engine/events#resize
       events GET    /events(.:format)            fullcalendar_engine/events#index
              POST   /events(.:format)            fullcalendar_engine/events#create
    new_event GET    /events/new(.:format)        fullcalendar_engine/events#new
   edit_event GET    /events/:id/edit(.:format)   fullcalendar_engine/events#edit
        event GET    /events/:id(.:format)        fullcalendar_engine/events#show
              PATCH  /events/:id(.:format)        fullcalendar_engine/events#update
              PUT    /events/:id(.:format)        fullcalendar_engine/events#update
              DELETE /events/:id(.:format)        fullcalendar_engine/events#destroy

在视图中,welcome / index.html.erb,

<%= link_to "Show Calendar", events_path %>

在fullcalendar_engine / events / index.html.erb中,

<p><%= link_to 'Create Event', 'javascript:void()', id: 'new_event' %></p>
<div><div class='calendar'></div></div>
<div id="event_desc_dialog" class="dialog" style="display:none;"></div>
<div id="create_event_dialog" class="dialog" style ="display:none;">
  <%= render 'form' %>
</div>

<script>
  $(document).ready(function(){
    $('.calendar').fullCalendar(full_calendar_options);
    // page is now ready, initialize the calendar...
    $('#new_event').click(function(event) {
      FullcalendarEngine.Form.display()
      event.preventDefault();
    });
   });
</script>

1 个答案:

答案 0 :(得分:0)

我猜您正在使用 link show action ,那么它应该是这样的

<%= link_to "Show Calendar", events_path(@event) %>

来自您提供的 rake routes

 event GET    /events/:id(.:format)        fullcalendar_engine/events#show
show route 需要 :id missing link > different controller action

<强>更新

您从 the view which is not part of that controller action 呼叫 <%= link_to "Show Calendar", :controller => 'events', :action => 'index' %> ,因此您应该像这样给予

{{1}}