我是RoR的新手。我在这个网站的任何地方搜索,我找不到我的问题的答案。Rails:没有路线匹配
我试图在没有视图的Ruby on Rails中创建api。基本上,我成功地在做方法获取和发布创建新数据。
我的问题现在我得到no routes match
错误更新和删除。下面是我上岗控制器代码:
def update
@post = Post.where(id: params[:id], user_id: session[:user_id]).first
if @post.update_attribute(:description, params[:description])
render json: @post
else
render json: {error: 'Process not completed'}
end
end
def destroy
@post = Post.where(id: params[:id], user_id: session[:user_id]).first
if @post.destroy
render json: {status: 'Successful'}
else
render json: {status: 'Your cannot delete this data'}
end
end
以下是我的路线
namespace :api do
namespace :v1 do
get 'users/request_token', to: 'users#request_token'
resources :users
resources :posts
end
end
我知道这是基本的代码为你们的代码。但我希望有人能帮助像我这样的新人改进RoR。
你打电话的网址是什么? – Rohit
发表你的错误和错误 –
localhost:3000/api/v1/posts?token = 333 sir @Rohit –