2014-04-01 87 views
0

我正在嘗試使用表單提交反饋。我在一個命名空間下正確定義了資源。但我仍然收到以下錯誤。未定義的方法__path rails 4

undefined method `feedbacks_path' for #<#<Class:0x00000009d3def8>:0x00000009d5fb20>  

下面給出的是我使用的代碼

feedbacks_controller.rb

class AdminConsoles::FeedbacksController < ApplicationController 
    layout 'admin_console' 
    def new 
    @feedback = Feedback.new 
    end 

    def create 
    @feedback = Feedback.new(feedback_params) 
    unless @feedback.save 
     redirect_to(:back) 
    else 
     redirect_to admin_console_feedback_path(@feedback) 
    end 
    end 

    def index 
    end 

    private 

    def feedback_params 
    params[:feedback].permit(:name,:email,:phone,:message) 
    end 

形式HTML頁面

<div class='row'> 
<%= form_for @feedback do |f| %> 
    <%= f.label "Name (optional)"%> 
    <%= f.text_field :name, placeholder: 'eg:pavan'%> 
    <%= f.label "Email (optional)" %> 
    <%= f.email_field :email, placeholder: 'eg:[email protected]' %> 
    <%= f.label "Phone (optional)" %> 
    <%= f.text_field :phone,placeholder: 'eg:+91943343334'%> 
    <%= f.label :Message %> 
    <%= f.text_area :message %> 
    <%= f.submit 'Save', class: 'input span2 btn btn-primary' %> 
    <% end %> 
</div> 

的routes.rb

namespace :admin_consoles, path: 'admin' do 
    resources :bulk_emails, only: [:new, :create, :index, :show] 
    resources :feedbacks, only: [:new, :show, :create] 
    resources :vendor_accounts 
    resources :vendor_profiles do 
     put :enable, as: :enable, on: :member 
     put :disable, as: :disable, on: :member 
     put :publish, as: :publish, on: :member 
     put :modify_services, as: :modify_services, on: :member 
    end 

回答

1

嘗試:

<%= form_for [:admin_consoles, @feedback] do |f| %>