小编Chr*_*hof的帖子

斯卡拉:咖喱的施工人员

我有以下Scala类:

class Person(var name : String, var age : Int, var email : String)
Run Code Online (Sandbox Code Playgroud)

我想使用Person构造函数作为curried函数:

def mkPerson = (n : String) => (a : Int) => (e : String) => new Person(n,a,e)
Run Code Online (Sandbox Code Playgroud)

这有效,但还有另一种方法可以做到这一点吗?这种方法似乎有点乏味且容易出错.我可以想象像Function.curried这样的东西,但是对于构造函数来说.

constructor scala currying

20
推荐指数
3
解决办法
5159
查看次数

Rails使用嵌套资源路由错误

在我的应用程序中,我有一个RecipesController和一个CommentsController.所有评论都属于食谱,可以投票.这是我的routes.rb的片段:

  resources :recipes do
    member do
      put 'vote_up'
      post 'comment'
    end

    resources :comments do
      member do
        put 'vote_up'
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

如果我运行rake路由,我在输出中找到以下路由:

vote_up_recipe_comment PUT    /recipes/:recipe_id/comments/:id/vote_up(.:format) {:action=>"vote_up", :controller=>"comments"}
Run Code Online (Sandbox Code Playgroud)

CommentsController有一个名为vote_up的方法.

此外,链接到路线工作(从我看来)

    <%= link_to 'Vote up', vote_up_recipe_comment_path(@recipe, comment), :method => 'put' %> <br />
Run Code Online (Sandbox Code Playgroud)

但是,单击该链接会出现以下错误:

Routing Error

No route matches "/recipes/7/comments/4/vote_up"
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我不知道如何调试这个,因为据我所知,路线应该匹配.

routes ruby-on-rails

3
推荐指数
1
解决办法
679
查看次数

标签 统计

constructor ×1

currying ×1

routes ×1

ruby-on-rails ×1

scala ×1