1

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?

Community
  • 1
  • 1
tvalent2
  • 4,959
  • 10
  • 45
  • 87
  • Is your profile controller actually called `ProfileController`, located in "app/controllers/profile_controller.rb"? – user229044 Aug 25 '11 at 20:19
  • No, sorry that was a typo. It's ProfilesController, located in "app/controllers/profiles_controller.rb". I'll fix that above. – tvalent2 Aug 25 '11 at 20:22

1 Answers1

2

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'.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Agh. Thanks! Now, however, I get a new error: `Missing template profiles/show_about with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:erb, :rjs, :rhtml, :rxml, :builder]} in view paths "/Users/me/Desktop/myapp/app/views", "/Users/me/Desktop/myapp/vendor/plugins/paperclip/app/views"` – tvalent2 Aug 25 '11 at 20:36
  • Apparently you don't have a file called `profiles/show_about`. What exactly are you trying to do here? You don't need routes/actions to render partials, that isn't what a partial is. Are you trying to get both actions to render the `show` template? If so, you'll have to explicitly call `render 'show'` since the template doesn't match the name of the action. I really can't tell what you're trying to accomplish, but your `render :partial` lines and your controller actions don't make sense in their current form. – user229044 Aug 25 '11 at 20:39
  • 1
    Looking at the question you linked to, I can see the problem - you're copying his totally backwards broken code. Whatever you're trying to do, don't use that question as a reference. – user229044 Aug 25 '11 at 20:44
  • What I want to do is render profile data depending on the link clicked. So I have two types of data: "About" and "Info". And I just want to load that data depending on which link I click. The goal is for it to act like "tabs" but using partials to store the actual data. – tvalent2 Aug 25 '11 at 20:47
  • 1
    Then add `render 'show'` to the end of each action. You'd be better off putting the shared code into a partial, and rendering that from within `show_info.html.erb` and `show_about.html.erb` templates. The whole point of partials is the reusable stuff goes into them, not the stuff only used in one place. – user229044 Aug 25 '11 at 20:47
  • I think what I may do is go for jQuery UI instead. – tvalent2 Aug 25 '11 at 21:15