I want to nest elements into the rails link_to.

Asked 2 years ago, Updated 2 years ago, 80 views

<%=link_to "link", {:controller=>:hoge_controller,:action=>:hoge_action}, class: "hoge_class"%>

<%=link_to{:controller=>:hoge_controller,:action=>:hoge_action}, class:"hoge_class" do%>
  <span>hoge</span> link.
<%end%>

This will result in an error.

<%=link_to hoge_path, class:"hoge_class" do%>
  <span>hoge</span> link.
<%end%>

There is no problem with this, but how do I explicitly specify the controller and actions?

ruby-on-rails ruby erb

2022-09-30 16:46

1 Answers

link_to arguments can be enclosed in parentheses.

<%=link_to({:controller=>:hoge_controller,:action=>:hoge_action}, class:"hoge_class")do%>
  <span>hoge</span> link.
<%end%>


2022-09-30 16:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.