Reputation: 957
i'm new to ROR, I, trying to update the field of a user from null to 1. I have written c controller for the same
def update_users
Rails.logger.info("in Update users")
@user = User.find(params[:id])
@user.deleted=1
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, notice: 'User was successfully Deleted.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
And Defined this in route as-
match '/update_users' => 'users#update_users', :as => 'update_users', :via => [:put]
my view for the same is-
= link_to raw('<span class="delete">Delete User</span>'), update_users_path(@user.id),
:method => :put,
:data => { :confirm => 'Are you sure?' },
:remote =>true
But in the output i, getting /update_users.7 instead of /update_users/7. and in the Network side I'm getting-
ActiveRecord::RecordNotFound in UsersController#update_users
Couldn't find User without an ID
pls help
Upvotes: 0
Views: 44
Reputation: 25029
Your routing is incorrect - your new action should be a member action on your existing User routes.
See http://guides.rubyonrails.org/routing.html#adding-more-restful-actions for more information.
Upvotes: 3
Reputation: 4880
Try changing your route to:
put '/update_users/:id' => 'users#update_users'
So that you can pass your ID to it properly. Then your link helper would be:
update_users_path(@user)
As it is now you haven't told the routes where to grab the ID from.
Upvotes: 1