I want the next thing:
when the button is clicked, I want to print the params[:id]
of the welcome controller
.
this is my java script code:
$(".btn_skip").click(function() {
$.ajax({
url: '/welcome',
type: 'PUT',
data: {show_msg: $("#mycheckbox").is(":checked")}
});
});
and this is my welcome_controller.rb
:
class WelcomeController < ApplicationController
def update
@user = User.find(params[:id])
puts params[:id]
end
end
when I ran: rails s
and pressed the button (btn_skip), I got:
Started PUT "/welcome" for 127.0.0.1 at 2013-02-05 12:18:26 +0200
ActionController::RoutingError (No route matches [PUT] "/welcome"):
routes.rb:
resources :welcome
rake routes
:
welcome_index GET /welcome(.:format) welcome#index
POST /welcome(.:format) welcome#create
new_welcome GET /welcome/new(.:format) welcome#new
edit_welcome GET /welcome/:id/edit(.:format) welcome#edit
welcome GET /welcome/:id(.:format) welcome#show
PUT /welcome/:id(.:format) welcome#update
DELETE /welcome/:id(.:format) welcome#destroy
maybe, should I pass the id in url: '/welcome'
?
if so, how can I get the id? maybe by: url: '/welcome/#{:id}'?
any help appreciated!
<%[email protected]%>
assuming u are using erb templates for views with Javascript where @something is the object that you pass to /welcome view file to render. – redDragonzz