0
我正在请求来自不同Rails应用程序的任何用户。我正在使用grape
宝石。以下代码是请求的用户信息发送控制器操作。Rails应用程序路由无法从Grape API访问
,但遗憾的是,示值误差:
NoMethodError (undefined method `profile_url' for #<Grape::Endpoint:0xdadef8c>):
问题是什么?显示网址的我的rake routes
确实存在。
module V1
class User < Grape::API
version 'v1', using: :path
format :json
prefix :api
resource :user do
desc "find any user"
params do
requires :email, type: String
requires :password, type: String
end
get :create do
user = User.find_by_email(params[:email])
if user.present?
if user.valid_password?(params[:password])
{user: user, profile_url: profile_url(user.profile)}
else
{:notice => "Invalid password for email: #{params[:email]}"}
end
else
{:notice => "No user found with email: #{params[:email]}"}
end
end
end
end
end
rake routes | grep profile
:
profiles GET /profiles(.:format) profiles#index
POST /profiles(.:format) profiles#create
new_profile GET /profiles/new(.:format) profiles#new
edit_profile GET /profiles/:id/edit(.:format) profiles#edit
profile GET /profiles/:id(.:format) profiles#show
PATCH /profiles/:id(.:format) profiles#update
PUT /profiles/:id(.:format) profiles#update
DELETE /profiles/:id(.:format) profiles#destroy
你可以分享你的'耙路线的结果| grep配置文件? – nayiaw