Return multiple link_to in decorator

Tomoharu Tsutsumi
1 min readMay 17, 2020

This is a short story, but I didn’t know how to make it, so I’m going to take a note. The gem is active_decorator. =>(https://github.com/amatsuda/active_decorator)

The issue

The previous code was below.

module TestOrderDecorator  def status_link    case status      when Order::ORDERED        link_to('accept', agree_path(current_user, self), method: :post)       when Order::AGREED        link_to 'go to page', feedback_order_path(self.order)    end  endend

And, what if you have to add another “link_to” to “when Order::ORDERED”? When I wrote the codes, it became like below.

module TestOrderDecorator   def status_link     case status       when Order::ORDEREDlink_to 'accept', agree_path(current_user, self), method: :post , link_to 'refuse', refuse_path(current_user, self), method: :post       when Order::AGREED         link_to 'go to page', feedback_order_path(self.order)     end  endend

However, it didn’t work.

The solution

The right way is below.

module TestOrderDecorator  def status_link    case status      when Order::ORDEREDlink_to('accept', agree_path(current_user, self), method: :post) + link_to('refuse', refuse_path(current_user, self), method: :post)      when Order::AGREED        link_to 'go to page', feedback_order_path(self.order)    end  endend

It worked!!

If you think this article is good, please follow me!

I inform you of a new article

https://twitter.com/tomoharutsutsum

Started LinkedIn as well!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi
Tomoharu Tsutsumi

Written by Tomoharu Tsutsumi

5+ years Full Stack SWE (Ruby, Go, TypeScript, JavaScript) | Former Founding Engineer of AI Startup in Canada

No responses yet