1

I want to setup a non-resourceful route in rails but I dont know how. Rails api says the structure has to be like this. post 'post/:id' => 'posts#create_comment' however, I'm not sure what I should exatly write.

I want it to post to the method "addbank" which is in the bankacctscontroller I will be on the page localhost:3000/bankaccts/new

def addbank
  if (params['customer_uri'])
    current_user.customer_uri = (params['customer_uri'])
  end
  if current_user.save
    redirect_to root_url, :notice => "bank account added"
  else
    render json: {error: "Payment account could not be configured properly"}, status: 401
  end 
end
4

2 回答 2

3

定义自定义路由的格式有很多种。最精细的是:

<METHOD> 'PATH' => 'Controller#Action', :as => path_helper_name(:as 是可选的)

因此,对于您的问题,它将是:

post '/bankaccts/:id' => 'bankaccts#addbank'

于 2013-08-06T06:11:23.560 回答
1

如果你使用rails4.0,它会这样写:

get "/bankaccts/new", to: "bankaccts#new", as: :new_post

我建议你应该先通过网站“ http://guides.rubyonrails.org/routing.html ”学习rails路由

于 2013-08-06T06:26:08.027 回答