Help getting my route working for jQuery UI Tabs with AJAX
I have my jQuery UI Tabs working right now but need help implementing the Ajax side. What I need help with is getting #tab-2
to show information (@user.messages
) from the Messag开发者_开发技巧esController
in a layout that's in profile_messages.erb
in the messages
view.
My application.js
:
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
}
}
});
});
MessagesController:
def profile_messages
@question = Question.all(params[:user_id])
respond_to do |format|
format.html
format.xml {render :xml => @question}
end
end
My profile show.html.erb
:
<div id="tabs">
<ul id="infoContainer">
<li><a href="#tabs-1"></a></li>
<li><%= link_to "Messages", message_path(@message, :render => "false") %></a></li>
<ul>
<div id="tabs-1">
</div>
</div>
My profile_messages.erb
:
<div id="tabs-2">
<% for 'message' in @user.messages %>
<div class="message">
</div>
<% end %>
</div>
So how can I get profile_messages
to load as a tab?
I was able to get things working (almost!) due to loads of help here on SO. For some more code, check out this other question: Exclude application layout in Rails 3 div
精彩评论