[英]link_to tag not responding to javascript after setting remote option as true in rails 4
I am trying to call a JavaScript from my link_
to tag using (remote: true) option but when I click on my link it is processed as HTML not as js.我正在尝试使用 (remote: true) 选项从我的
link_
调用 JavaScript 到标记,但是当我单击我的链接时,它被处理为 HTML 而不是 js。 Can anyone tell me what I am doing wrong.谁能告诉我我做错了什么。 I am new to rails.
我是导轨的新手。 Here is my code->
这是我的代码->
my partial view social_media/_fb_like.erb in which link is given:我的部分视图 social_media/_fb_like.erb 其中给出了链接:
<div style="display: inline-block;position: relative;">
<% if post['likes']['summary']['has_liked']%>
<img src="\assets\liked.png" width="18px" height="18px"/> <%=link_to "Like", social_media_fb_like_path(:pid => "#{post['id']}"),id: "to_unlike", :remote => true%>
<%else%>
<img src="\assets\unliked.png" width="18px" height="18px"/> <%=link_to "Like",social_media_fb_unlike_path(:pid => "#{post['id']}"),id: "to_like", :remote => true%>
<%end%>
</div>
my controllers methods->我的控制器方法->
SocialMediaController#fb_like社交媒体控制器#fb_like
def fb_like
user = User.find_by_id(session[:user_id])
@post_id = Koala::Facebook::API.new(user.token)
postid=params[:pid]
@post_id.put_like(postid)
end
SocialMediaController#fb_unlike SocialMediaController#fb_unlike
def fb_unlike
user = User.find_by_id(session[:user_id])
@post_id = Koala::Facebook::API.new(user.token)
postid=params[:pid]
@post_id.delete_like(postid)
end
and my routes in routes.rb ->和我在 routes.rb 中的路线 ->
get 'social_media/fb_like'
get 'social_media/fb_unlike'
When i click on any link like/unlike my server console gives me this message:当我点击任何像/不像我的服务器控制台的链接时,会给我这条消息:
Started GET "/social_media/fb_unlike?pid=1665814087069318_1675050226145704" for 127.0.0.1 at 2016-10-18 15:05:13 +0530
Processing by SocialMediaController#fb_unlike as HTML
Parameters: {"pid"=>"1665814087069318_1675050226145704"}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 9 LIMIT 1
Completed 500 Internal Server Error in 5256ms (ActiveRecord: 0.4ms)
What i learned is that if i set the option remote as true in link_
to than it should be processing as js because of jquery_ujs
, not as HTML as shown above.我学到的是,如果我在
link_
to 中将选项 remote 设置为 true ,那么它应该作为 js 处理,因为jquery_ujs
,而不是如上所示的 HTML。 Please help me out.请帮帮我。 Thanks in advance
提前致谢
The answer I figured out for my question was the wrong order of the files in application.js manifest我为我的问题找到的答案是 application.js 清单中文件的错误顺序
The right order should be正确的顺序应该是
//= require jquery
//= require jquery.turbolinks // if u use the gem jquery.turbolinks
//= require jquery_ujs
// ...Other js files
//= require turbolinks
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.