Railsã«Jbuilderãå°å ¥ããããã¬ã¹ãã³ã¹ã帰ã£ã¦ããªãã£ã¦å°ã£ãã§ãããã®å·»
ã¾ãæåã«Jbuilderã£ã¦Javaã®ãªããã ã¨æã£ããå¯å£«éã¨ãããããã¨ãããåºãã¦ãIDEã¨ããªããããããã®ã10ä¸ãããããããªã
ã§ããããããªãã¦ã¬ã¹ãã³ã¹ãjsonã§çµã¿ç«ã¦ãã¨ãã«ä½¿ããã¤ã
https://github.com/rails/jbuilder
WebAPIãµã¼ããªããåµããã ã£ããããã²ä½¿ã£ã¦ã¿ãæ¹ããããrespond_withã¨ãè¾ãããã
before
respond_with article, include: [ :hoge, {comments: {include: {author:{only: :name, methods: 'avatar_thumb_url' }}}} , {likes: {only: :id, include: {user:{only: :id, methods: 'avatar_thumb_url' }}}} , {article_images: {except: ArticleImage::FILE_STATUS_COLUMN, methods: ArticleImage::IMAGE_URL_METHODS}}, {user: {except: User::FILE_STATUS_COLUMN, methods: Author::IMAGE_URL_METHODS}} ], except: Article::EXCLUDE_COLUMN
ãããªæãã®ãã»ã»ã»
after
json.array! @articles do |article| json.extract! article, :id, :title, :rating, :article_url, :thumb_url json.author article.author, :name, :title, :avatar_thumb_url json.hoge article.hoge, :name, fuga, piyo json.article_images article.article_images, :article_url, :thumb_url end
ãããªã«ããããããã»ã»ã»ï¼
ã§ãæåãã©ã¦ã¶ã§Jsonã§ãã§ãã¼ã£ã¦æããªãããã£ã¦ããã ãã©ã詳細ãè©°ãã«ããã£ãã¨ãã«ãããããããããã¨ãã¨Rspecã§ãã¹ããæ¸ãã¦ãã£ãã®ã§ãã¼ãã£ã³ã°ã楽åã¨æã£ããã¬ã¹ãã³ã¹ã空ã§ãã¹ããå ¨ã´ã±ãã
ã¡ãã£ã¨èª¿ã¹ããããã£ãã
http://stackoverflow.com/questions/9965945/why-is-jbuilder-not-returning-a-response-body-in-json-when-testing-rspec
Jbuilderã¯ãããã¨Rspecã§ã¯render_viewã¨ããããã»ã¹ãå¿
è¦ã ã£ããããã
ããããã
RSpec.configure do |config| ~snip~ config.render_views = true ~snip~
ããã§ãã¹ãå ¨éãæ°æãããã¯ããªã¼ãã
- åºç社/ã¡ã¼ã«ã¼: ã¢ããã¬ãã¯ã¹
- çºå£²æ¥: 2013/07/24
- ã¡ãã£ã¢: Blu-ray
- ãã®ååãå«ãããã° (73件) ãè¦ã