2014-09-02 2 views
0

안녕하세요. 내 라우팅에 문제가 있습니다. 현재 중첩 된 게시물 리소스가있는 사용자를 고안했습니다. 현재 각 사용자에 대해 새 게시물을 만들려고합니다.레일은 내비게이션 사용자를위한 중첩 된 경로입니다.

routes.rb

Rails.application.routes.draw do 

    root 'home#index' 

    resources :dashboard 

    devise_for :users, :path => '', :path_names => { 
    :sign_in => 'login', 
    :sign_out => 'logout', 
    :sign_up => 'register' 
    } 

    resource :users do 
    resources :posts 
    end 
end 

posts_controller.rb

class PostsController < ApplicationController 
    before_action :set_user 

    def index 
    @posts = @user.posts 
    end 

    def new 
    @post = @user.posts.new 
    end 

    def create 
    @post = @user.posts.new(post_params) 
    if @post.save 
     redirect_to :controller => 'dashboard', :action => 'index' 
    else 
     render :new 
    end 
    end 

private 

    def post_params 

    end 

    def set_user 
    @user = current_user 
    end 
end 

링크

<%= button_to "New Post", new_users_post_path(current_user), :class => "btn btn-default navbar-btn", :method => :get %> 

경로

new_users_post GET /users/posts/new(.:format)  posts#new 

이 리드 : # < 번호 :/사용자/글/새 정의되지 않은 메서드`user_posts_path '에서 NoMethodError : 0x007fe01d1608f0>. 어떤 아이디어? 감사!

답변

0

그것은 문제가 해결되지 않지만, new_users_post_path는 PARAMS없이해야한다 :

<%= button_to "New Post", new_users_post_path, class: "btn btn-default navbar-btn", method: :get %> 

또한 resource :user 대신 users

+0

감사합니다! 하지만 여전히 같은 오류가 발생합니다. (# <# : 0x007fe01d0339f0>에 대해 정의되지 않은 메소드'user_posts_path ') – vertroa