尝试link_to partials后出错

时间:2011-08-25 20:16:39

标签: ruby-on-rails-3 partial-views uninitialized-constant

使用此previous question作为指南,我尝试在容器上方创建ul导航标题,在单击时呈现容器内的部分内容。 (希望这有点意义,但它可能并不重要。)在点击部分链接之前,我默认它会呈现部分。

然而,当我去点击我的link_to希望渲染部分时,我得到以下错误:

uninitialized constant ProfileController

我正在使用Rails 3.这是我的相关代码:

ProfilesController:

def show_about
  @is_on_show_about = true
end

def show_info
  @is_on_show_info = true
end

视图/简档/ show.html.erb:

<div id="info">
  <div id="infoContainer">
    <% if @is_on_show_about %>
      <%= render :partial => 'show_about' %>
    <% elsif @is_on_show_info %>
      <%= render :partial => 'show_info' %>
    <% end %>
    <ul id="info">
      <li>
        <%= link_to 'About', show_about_path, :remote => true %>
      </li>
    </ul>
    <ul id="settingsLinks">
      <li><a href="#">Advice</a></li>
      <li>
        <%= link_to 'Info', show_info_path, :remote => true %>
      </li>
    </ul>
  </div>
  <%= render :partial => 'show_about' %>

routes.rb中:

map.show_info 'profiles/:id/info', :controller => 'profile', :action => 'show_info'
map.show_about 'profiles/:id/about', :controller => 'profile', :action => 'show_about'

任何人都可以帮我解决这个问题并解释出现了什么问题吗?

1 个答案:

答案 0 :(得分:2)

您的两条路线都不正确。

如果您的控制器的确名为ProfilesController(复数),那么您的路线应使用:controller => 'profiles',而不是:controller => 'profile'