Reputation: 313
Sort of noob-rails question ;):
I've got 2 actions in my controller - index and own. In index, i'm listing all posts and own generates only logged users' posts. Controllers are pretty similar, but view is identical and I assume can be shared between this two controllers.
In the own controler I put something like this:
respond_to do |format|
format.html { render :action => "index" }
format.json { render json: @ads }
end
And added to routes:
match "/ads/own" => 'ads#own', :via => :get
Is there any better solution to do this?
Upvotes: 2
Views: 1497
Reputation: 4451
You can do this:
def index
....
end
def own
....
render :index
end
Everything (all variables) will directly pass to the index view in own. If you want the :json component, then add:
class SomeController < ApplicationController
respond_to :html, :json
and put 'respond_with @posts' as the last item in each action.
Upvotes: 4