未定义的局部变量或方法' main_page'

时间:2016-02-10 07:30:46

标签: ruby-on-rails

在我的 application.html.erb 中,我有一个菜单,显示在每个页面上。但我无法使用'退出'链接,出现错误。

  

未定义的本地变量或方法' main_page'

我有' main_page'在我的路线中,我不明白为什么它不起作用。 我试图使用'退出'在用户控制器的操作中从我的节目视图链接,它工作正常。

show.html

response.setHeader("Access-Control-Allow-Origin","http://www.sample.com" );
response.setHeader("Access-Control-Allow-Methods", "#verb#, OPTIONS" );
response.setHeader("Access-Control-Allow-Headers", "accept, Origin, application/json, X-Requested-With, Content-Type, Access-Control-Allow-Origin" );               
response.setHeader("Access-Control-Max-Age", "86400" );

为什么在从application.html使用链接时出现错误?虽然'我的约会'链接工作。我该如何解决?

application.html

<% content_for :user_form do %>

<p id="notice"><%= notice %></p>

<p>
  <strong>Name:</strong>
  <%= @user.name %>
</p>

<p>
  <strong>Email:</strong>
  <%= @user.email %>
</p>

<%= link_to 'Edit', edit_user_path(@user) %> 
<%= link_to 'My dates', :controller => :calendar, :action => :month_for_user %>
<%= link_to 'sign out', :controller => :sessions, :action => :destroy %>
<%end%>

sessions_controller

<div id = 'user_menu' >

  <p id="notice"><%= notice %></p>

<p>
  <strong>Name:</strong>
  <%= current_user.name %>
</p>

<p>
  <strong>Email:</strong>
  <%= current_user.email %>
</p>

<%= link_to 'Edit', edit_user_path(current_user) %> 
<%= link_to 'My dates', :controller => 'calendar', :action => 'month_for_user' %>
<%= link_to 'sign out', :controller => 'sessions', :action => 'destroy' %>


<% end %>

  </div>

路由

def destroy
    redirect_to main_page
    sign_out
end

Rails对我来说是新的,也许这是一个愚蠢的问题,但我老实说试图找到一个答案,但没有结果。请帮我解决这个问题!谢谢

1 个答案:

答案 0 :(得分:0)

  

未定义的局部变量或方法'main_page'

错误来自destroy中的sessions_controller方法。它应该是

def destroy
  redirect_to main_page_url #or action: "main_page"
  sign_out 
end
相关问题