尝试 link_to 部分后出错
使用此上一个问题作为指导,我尝试创建一个ul< /code> 容器上方的导航标题,单击时会在容器内呈现部分内容。 (希望这是有道理的,但这可能并不重要。)在单击部分链接之前,我让它默认渲染部分。
但是,当我点击 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
< strong>views/profiles/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'
谁能帮我解决这个问题并解释一下出了什么问题?
Using this previous question as a guide, I've attempted to create a ul
navigation header above a container that renders partials within the container when clicked. (Hopefully that makes some sense, but it may not be important.) Until the links for the partials are clicked, I have it rendering a partial by default.
However, when I went to click my link_to
in hopes of rendering the partial I get the following error:
uninitialized constant ProfileController
I'm using Rails 3. Here's my relevant code:
ProfilesController:
def show_about
@is_on_show_about = true
end
def show_info
@is_on_show_info = true
end
views/profiles/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'
Can anyone help me fix this and explain what went wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的两条路线都不正确。
如果您的控制器确实名为
ProfilesController
(复数),那么您的路由应该使用:controller => 'profiles'
,而不是:controller => '个人资料'
。Both of your routes are incorrect.
If your controller is indeed named
ProfilesController
(plural) then your routes should use:controller => 'profiles'
, instead of:controller => 'profile'
.