0

Good day, there are a lot of questions on this problem here, but they don't help me.

For signed_in user I have a homepage with bookmarks and folders, which contains bookmarks belonged to this folder.

home method is in static_pages controller, which looks like this:

def home
    if signed_in?
      @folder = current_user.folders.build
      @folders = current_user.folders.all
      @bookmark = current_user.bookmarks.build
      @bookmarks = current_user.bookmarks.all
    end
  end

This is part of home.html.erb

<div class="span3">
        <table class="table table-hover table-condensed">
          <%= render @bookmarks %>
        </table>
      </div>
      <div class="span3">
        <table class="table table-hover table-condensed">
          <%= render @folders %>
        </table>
      </div>

So I have 2 tables with all bookmarks and all folders, belonged to current_user

This is _folder.html.erb from folders folder in views

<tr data-toggle="tooltip" data-placement="right" data-html="true">
  <td data-href="<%= folder %>" class="bookmark"><i class="icon-folder-close"></i>
    <%= link_to folder.name, folder_path %>
  </td>
  <td>
    <%= link_to '<i class="icon-edit"></i>'.html_safe, '#' %>
  </td>
  <td>
    <%= link_to '<i class="icon-trash"></i>'.html_safe, folder_path, method: :delete,
                data: {confirm: 'Are you sure?'},
                title: 'Delete folder ' + folder.name.to_s %>
  </td>
</tr>

folders_controller.rb, with show method:

def show
    @folder = Folder.find(params[:id])
    @bookmarks = @folder.bookmarks.all
  end

also resources :folders exists routes.rb

All I need is to go to localhost:3000/folder/1, when clicking on folder_name on homepage.

This is what I get:

Routing Error
No route matches {:action=>"show", :controller=>"folders"}

In rake routes everything is ok.

When put localhost:3000/folder/1 in browser, it works correctly.

Thank you!

4

1 回答 1

2

Try Replacing:

 <%= link_to folder.name, folder_path %>

with

 <%= link_to folder.name, folder_path(folder) %>

as you need to provide the id to the show action.

You can get more information here

于 2013-04-30T21:04:48.030 回答