Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
responding with json in without_layout/other_posts_controller too
- Loading branch information
Showing
3 changed files
with
32 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |