你好,我在rubyonrails4的路由上遇到了问题
错误:

undefined method `routes_path'

视图:
<h1>Load data</h1>
<div class="row">
<div class="span6 offset3">
  `<%= form_for @route, :html => { :multipart => true } do %>
    <%= hidden_field_tag 'current_user', @current_user %>
    <%= file_field_tag :file %>
    <%= submit_tag "Import", style: 'margin-top: -10px', class: "btn btn-primary" %>
<% end %>

控制器:
def new
    @route = current_user.build_route
end

def create
     nil_flag = Route.import(params[:file], current_user)
    if nil_flag == 1
      flash[:success] = "Data created."
      redirect_to route_path(current_user)
    else
      flash[:error] = "Error"
      redirect_to load_data_path
    end
end

型号:
def self.import(file, current_user)
   @user = current_user
   @route = @user.build_route
   @nil_flag = 0

   File.open(file.path, 'r') do |f|
   .
   .
   .
    #etc
end

路线
匹配“/load_u data”,到:“routes_35;new”,通过:“get”
视图、控制器和模型被命名为“Route”
视线中的路线有问题吗谢谢你

最佳答案

Matt(上一个答案作者)基本上回答了这个问题,只是想注意,您还可以将as选项附加到您的路由中,为它命名:
match '/load_data', to: 'routes#new', via: 'get', as: 'routes'
这将为您“定义”routes_path

关于ruby-on-rails - Ruby on Rails 4中的路线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19539467/

10-13 04:50