Reputation: 5009
I'm getting ActionController::RoutingError in Profiles#show
when I click a link to render a layout as part of my implementation of jQuery UI tabs. Here's my link_to
:
<%= link_to "Messages", :controller => 'profiles', :action => 'profile_messages', :remote => true %>
My ProfilesController:
def profile_messages
@messages = User.find(@profile.user_id).messages
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @messages }
end
end
My profile_messages
erb layout:
<div id="tabs-2">
<% for message in @user.messages %>
<div class="message-1">
</div>
<% end %>
</div><!-- end messages -->
Routes.rb:
resources :messages do
get "messages/profile" => :profile_messages
resources :responses
end
What I want to happen is: when you click the link created by my link_to
, the layout in profile_messages.html.erb
shows and loads the messages in that specific layout. What's going on here?
UPDATE: Adding the new line in Routes.rb
gives me a new route:
message_messages_profile GET /messages/:message_id/messages/profile(.:format) {:action=>"profile_messages", :controller=>"messages"}
So I tried this in my Profiles show.html.erb I put:
<li><%= link_to "Messages", message_messages_profile_path, :remote => true %></li>
This gives me a RoutingError in Profiles#show
-- No route matches {:action=>"profile_messages", :controller=>"messages"}
. Even when I add the following into my MessagesController
:
def profile_messages
@message = @user.messages.find(params[:user_id])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @messages }
end
end
Upvotes: 0
Views: 226
Reputation: 5009
Thanks to the combined efforts of folks here on SO I was able to get this to work. Check out these questions for more code:
Exclude application layout in Rails 3 div
Rails 3 jQuery UI Tabs issue loading with Ajax
Upvotes: 0
Reputation: 3137
resource :messages do
collection do
get :profile_messages
end
end
in your view
<li><%= link_to "Messages", "/messages/profile_messages", :remote => true %></li>
Upvotes: 1
Reputation: 10547
get "messages/profile" => "messages#profile_messages", :as => profile_messages
resource :messages do
resource :responses
end
You don't have a route for that controller action. Rails doesn't map ":controller/:action/:id" by default any more. You can also just enable that route if you want. You could be able to reference this via profile_messages_path
.
It's assuming 'show' is actually an id for messages here I think. The default routes for a resource are listed here: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions. Make sure you list your routes first!
Upvotes: 1