Я загружаю шаблон profile_messages
как часть вкладок пользовательского интерфейса jQuery с помощью Ajax. Однако при загрузке profile_messages
наследует макет приложения моего сайта (верхний и нижний колонтитулы, все). Я пытался сделать это частично, но тогда ничего не получилось. Поэтому мне интересно, есть ли способ сделать это.
jQuery в моем application.js
:
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"There was an error loading this tab. Please try again." );
}
}
});
});
Routes.rb
:
resources :profiles do
get :profile_messages, :on => :collection
end
match "/profiles/profile_messages" => "profiles#profile_messages"
My profiles#show.html.erb
:
<div id="tabs">
<ul id="infoContainer">
<li><a href="#tabs-1">About</a></li>
<li><%= link_to "Messages", '/profiles/profile_messages/', :id => 'qs', :remote => true %></li>
</ul>
<div id="tabs-1">
</div>
</div>
Мой шаблон profile_messages
:
<div id="tabs-2">
<% for message in @user.messages %>
<% end %>
</div>
My profile_messages.js.erb
:
$( "#tabs" ).html( "<%= escape_javascript( render(@profile.messages) ) %>" );
Мой метод profile_messages
в profiles_controller.rb
:
def profile_messages
@profile = User.find(user.id).profile #need to fix so @profile is defined for each profile, not just the current_user profile
@messages = User.find(@profile.user_id).messages
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @messages }
end
end
Так есть ли способ обойти макет приложения?
ОБНОВЛЕНИЕ: я заставил макет исчезнуть, вставив следующее в свой profile_messages
def profile_messages
@profile = User.find(user.id).profile
@messages = User.find(@profile.user_id).messages
respond_to do |format|
format.html { render :layout => nil }
format.xml { render :xml => @messages }
end
end
ОБНОВЛЕНИЕ 2: я попытался отрендерить часть, но это не сработало. Вот что я изменил в своем profiles#show.html.erb
:
<div id="tabs">
<ul id="infoContainer">
<li><a href="#tabs-1">About</a></li>
<li><%= link_to render(:partial => 'profiles/profile_messages'), :id => 'qs', :remote => true do %>Messages<span> </span><% end %></li>
</ul>
<div>
</div>
</div>
Однако это загружает частичное в <ul id="infoContainer">