【问题标题】:RoutingError (No route matches [GET] in RailsRoutingError(Rails 中没有路由匹配 [GET]
【发布时间】:2014-12-12 12:55:40
【问题描述】:

我收到错误消息:RoutingError (No route matches [GET] "/new_invitation"):

运行rake routes 产生:

...
    invitations GET    /invitations(.:format)                invitations#index
                POST   /invitations(.:format)                invitations#create
 new_invitation GET    /invitations/new(.:format)            invitations#new
edit_invitation GET    /invitations/:id/edit(.:format)       invitations#edit
     invitation GET    /invitations/:id(.:format)            invitations#show
                PUT    /invitations/:id(.:format)            invitations#update
                DELETE /invitations/:id(.:format)            invitations#destroy
...

但它在第 3 行。有什么想法吗?

编辑

invitations_controller.rb 包含...

def new
  @invitation = Invitation.new (permitted_params.invitation)
end

def create
  @invitation = Invitation.new(permitted_params.invitation)
    if current_user
      @invitation.sender = current_user
      if @invitation.save
        UserMailer.invitation(@invitation, register_url(@invitation.token)).deliver
        flash[:notice] = "You have successfully sent the invitation."
        redirect_to styleguide_path
      else
        render :action => 'new'
      end
    else
     @invitation.sender = 0
     if @invitation.save
       UserMailer.invitation(@invitation, register_url(@invitation.token)).deliver
       flash[:notice] = "Your request for an invitation has been processed.  Please check your email for your invitation link."
       redirect_to root_path
     else
       render :action => 'new'
     end
    end

  end

我尝试重命名控制器、模型和视图模板,但无济于事。有什么想法吗?

错误信息

Started GET "/new_invitation" for 127.0.0.1 at 2014-10-16 19:40:36 -0600

ActionController::RoutingError (No route matches [GET] "/new_invitation"):

【问题讨论】:

  • 显示详细的错误信息..
  • 你想得到/invitations/new,但你得到了/new_invitation。你点击了链接吗?你能给我一个链接吗?
  • 该链接通过自定义 javascript 调用来加载表单的弹出生成器。相关js代码为:$('#DialogPop').bPopup({loadUrl:'/new_invitation', modalClose: false});

标签: ruby-on-rails routes


【解决方案1】:

试试这个(如果脚本的位置在同一个控制器上)

$('#DialogPop').bPopup({
  loadUrl: '<%= url_for :action => 'new' %>',
  modalClose: false
});

或者(推荐)

$('#DialogPop').bPopup({
  loadUrl: '<%= new_invitation_path %>',
  modalClose: false
});

注意:如果视图中的自定义 javascript 或带有 .js.erb 扩展名的 javascript 文件中的自定义 javascript

reference

【讨论】:

  • 那行得通。只需将文件名更改为:filename.js.erb
猜你喜欢
  • 2013-04-21
  • 2018-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-21
  • 1970-01-01
相关资源
最近更新 更多