I'm new in RoR. I have search everywhere in this site and I could not find an answer to my question.
I tried to create api in Ruby on Rails without view. Basically, I successful in do method get and post to create new data.
My problem now I'm getting no routes match
error for update and delete. Below is my code for posts controller:
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
and below is my code for routes
namespace :api do
namespace :v1 do
get 'users/request_token', to: 'users#request_token'
resources :users
resources :posts
end
end
I know this is basic code for you guys. But I hope there's someone can help new people like me to improve in RoR.