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?
You can do this:
Everything (all variables) will directly pass to the index view in own. If you want the :json component, then add:
and put ‘respond_with @posts’ as the last item in each action.