Rails 3,Jquery.load,无布局
我的Ajax调用几乎可以工作了,但是我不明白为什么我的布局仍然被渲染?以下是上下文: 我的网站上有一个使用linkedIn API的联系人页面。我想在加载页面时从ajax调用加载LinkedIn信息。这工作做得很好 但是my.load()的结果与我的站点布局一起呈现。我只想在我的ajax\u contact.html.erb中呈现html contact.jsRails 3,Jquery.load,无布局,jquery,ruby-on-rails-3,layout,Jquery,Ruby On Rails 3,Layout,我的Ajax调用几乎可以工作了,但是我不明白为什么我的布局仍然被渲染?以下是上下文: 我的网站上有一个使用linkedIn API的联系人页面。我想在加载页面时从ajax调用加载LinkedIn信息。这工作做得很好 但是my.load()的结果与我的站点布局一起呈现。我只想在我的ajax\u contact.html.erb中呈现html contact.js $(document).ready(function() { $(".info_perso").load( '/contact
$(document).ready(function() {
$(".info_perso").load( '/contact/ajax_contact', {name:"benoit"}, function(data){ $(".info_perso").html( data );})
});
ajax_contact.html.erb:
<%if !@profile.nil?%>
<%=image_tag(@profile.picture_url)%><br />
<%=@profile.first_name %> <%=@profile.last_name %><br>
<%=@profile.headline%><br>
<%=@profile.industry%><br> <br />
<%=@profile.summary%><br>
<label class="linkedin_title">Education</label><br>
<% @profile.educations.all.each {|edu| %>
Degre : <%=edu.degree%><br>
Années : <%=edu.start_date.year%> - <%=edu.end_date.year%><br>
Concentration : <%=edu.field_of_study%><br>
Universite : <%=edu.school_name%><br>
<%}%>
<label class="linkedin_title">Experience</label><br>
<% @profile.positions.all.each {|pos| %>
<label class="linkedin_subtitle"> Company:</label> <%=pos.company.name%><br><br>
<label class="linkedin_subtitle">Titre :</label> <%=pos.title%><br>
<label class="linkedin_subtitle">Années :</label> <%=pos.start_date.month%>/<%=pos.start_date.year%> - <%= pos.end_date? ? pos.end_date.month.to_s + "/" + pos.end_date.year.to_s : "now"%><br>
<label class="linkedin_subtitle">Description :</label> <%=pos.summary%><br/><br/>
<%}%>
<%else%>
<%=link_to "Activer linkedIn", :controller=>"linkedinAuth", :action=>"benoit", :name=>"benoit", :callback=>"/linkedinauth/callbackbenoit"%>
<%end%>
即使使用:layout=>false,我的布局仍然显示!!!任何人都可以看到问题?添加
呈现“ajax\u contact”,:layout=>false
对于您的操作,在最后,部分视图的名称也应该以_开头,因此您的视图应该命名为“_ajax\u contact”将您的视图重命名为“_ajax\u contact”,这样rails就知道它是一个部分视图。您是否也更改了渲染方法?你只需要更改文件名。事实上,我什么都试过了_带有render“ajax\u contact”的ajax\u contact.html.erb,:layout=>false。然后呈现“\u ajax\u context”,:layout=>false。然后呈现:partial=>ajax\u context',:layout=>false。。。我不明白。。。最糟糕的是,我已经用另一个项目做了这件事,我所需要做的就是在我的控制器中放入render:layout=>false!!天啊。。。总是一个愚蠢的错误哈哈。。我的render:layout=>false位于方法的末尾。。。在我获救之后。。。。所以它从来没有被叫来过!应该在调试之前,谢谢你的时间。我会接受你的回答作为感谢;-)
def ajax_contact
name = params[:name]
linkedinInfo = LinkedinApiInfo.find(1)
linkedinCred = LinkedinCredential.find_by_name(name)
if !linkedinCred.nil?
client = LinkedIn::Client.new(linkedinInfo.apiKey, linkedinInfo.secretKey)
client.authorize_from_access(linkedinCred.acctoken, linkedinCred.accsecret)
# Pick some fields
fields = ['first-name', 'last-name', 'headline', 'industry', 'num-connections','educations', 'num-recommenders','recommendations-received', 'summary', 'positions','picture-url']
@profile = client.profile :fields => fields
@profile.recommendations_received.all.each {|rec| puts rec.recommendation_text}
puts @profile
end
rescue SocketError
puts "Unable to connect"
render "ajax_content", :content_type=>"text/html", :layout=>false
end