rails Coffeescript "Alert" 没有响应 link_to
Getting no response for rails Coffeescript "Alert" for a link_to
我是 rails 和咖啡的新手,但是,我只是想在单击 link 时收到提醒!相反,什么都没有。它把 link_to 变成死的 link
我的Controller.rb
def index
@posts = Post.all
end
def new
@post = Post.new
respond_to do |format|
format.html
format.js
format.xml { render :xml => @post.to_xml }
end
end
def create
@post = Post.create!(params[:post])
format.html
format.js
redirect_to post_url
end
def post_params
params.require(:post).permit(:title,:body)
end
我的索引,html.erb 看起来像这样
<%= link_to 'New', post_new_url, id: "go", :remote => true %>
我的 post.coffee 里面只有这段代码
$(document).on "page:change", ->
$("#go").click ->
alert "Clicked!"
我发现出了什么问题。显然我的代码很糟糕。
$(document).on "click", "#go", ->
alert "page has loaded!"
我是 rails 和咖啡的新手,但是,我只是想在单击 link 时收到提醒!相反,什么都没有。它把 link_to 变成死的 link
我的Controller.rb
def index
@posts = Post.all
end
def new
@post = Post.new
respond_to do |format|
format.html
format.js
format.xml { render :xml => @post.to_xml }
end
end
def create
@post = Post.create!(params[:post])
format.html
format.js
redirect_to post_url
end
def post_params
params.require(:post).permit(:title,:body)
end
我的索引,html.erb 看起来像这样
<%= link_to 'New', post_new_url, id: "go", :remote => true %>
我的 post.coffee 里面只有这段代码
$(document).on "page:change", ->
$("#go").click ->
alert "Clicked!"
我发现出了什么问题。显然我的代码很糟糕。
$(document).on "click", "#go", ->
alert "page has loaded!"