Skip to content

Commit

Permalink
responding with json in without_layout/other_posts_controller too
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoLnx committed Sep 29, 2011
1 parent 6a02728 commit b24d505
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
22 changes: 11 additions & 11 deletions app/controllers/without_layout/other_posts_controller.rb
@@ -1,15 +1,15 @@
class WithoutLayout::OtherPostsController < PostsBaseController
layout nil
module WithoutLayout
class OtherPostsController < PostsBaseController
layout nil

def show
location = params[:location]
friendly_title = params[:id]
@post = Post.find(:location => location, :friendly_title => friendly_title)
@post_url = post_url @post.friendly_id
def show
location = params[:location]
friendly_title = params[:id]
@post = Post.find(:location => location, :friendly_title => friendly_title)
@post_url = post_url @post.friendly_id

prepare_to_render_show_with @post, @post_url

render 'posts/show'
response.headers['title'] = @post.title
prepare_to_render_show_with @post, @post_url
render_json_to_page_changes
end
end
end
11 changes: 11 additions & 0 deletions app/controllers/without_layout/posts_base_controller.rb
@@ -0,0 +1,11 @@
class WithoutLayout::PostsBaseController < PostsBaseController
def render_json_to_page_changes
render 'posts/show.html.erb'
response.content_type = "application/json"
response.body = {
:body => response.body,
:title => @post.title,
:sharing_head => @sharing_head.to_hash
}.to_json
end
end
25 changes: 10 additions & 15 deletions app/controllers/without_layout/posts_controller.rb
@@ -1,19 +1,14 @@
class WithoutLayout::PostsController < PostsBaseController
layout nil
module WithoutLayout
class PostsController < PostsBaseController
layout nil

def show
id = params[:id].sub('/','').match(/\d+/)[0]
@post = Post.find id
@post_url = post_url(@post.friendly_id)
def show
id = params[:id].sub('/','').match(/\d+/)[0]
@post = Post.find id
@post_url = post_url(@post.friendly_id)

prepare_to_render_show_with @post, @post_url

render 'posts/show.html.erb'
response.content_type = "application/json"
response.body = {
:body => response.body,
:title => @post.title,
:sharing_head => @sharing_head.to_hash
}.to_json
prepare_to_render_show_with @post, @post_url
render_json_to_page_changes
end
end
end

0 comments on commit b24d505

Please sign in to comment.