Understanding How to Replace Path with a Variable in the Rails Subtemplate

Asked 2 years ago, Updated 2 years ago, 78 views

Call a partial template from index and
from that partial template. Furthermore, some templates have been called.


in the bottom tier _shared/tag_list Specify prepque_origques_path and set this to some variable
By replacing it, I would like to be able to call other views as well.
I can't do it well.

Specify prepque_origques_path as index
_shared/origque_content→_shared/tag_list and
How should I describe passing variables?

index

<%@origques.each do|origque|%>
 <%=render partial: "_shared/origque_content", locals: {origque_content:origque,
             originque_url —prepque_origque_path (origque.prepque.id, origque.id),
             originque_memo_url:prepque_origque_memos_path(origque_id:origque.id)}%>
<%end%>

_shared/origque_content

<%=render'_shared/tag_list', tag_list:origque_content.grammar_list%></div>

_shared/tag_list

<%tag_list.each do|tag|%>
     <%=link_to tag,**prepque_origques_path**(tag_name:tag, order:params[:order], column:params[:column], class:"label label-primary"%>
<%end%>

I tried writing as below, but I got an error.

<%=render'_shared/tag_list', tag_list:origque_content.grammar_list, path:prepque_origques_path%>
<%=link_to tag, path(tag_name:tag, order:params[:order]"%>

ruby-on-rails ruby

2022-09-30 21:44

2 Answers

How about the following?

<%=render'_shared/tag_list', tag_list:origque_content.grammar_list, path::prepque_origques_path%>

and

<%=link_to tag, send(path,tag_name:tag,order:params[:order])%>

I'm sorry if it doesn't work because I haven't tried it on hand.

Ruby cannot pass the method as an argument because it is not an object.Instead, pass the symbol.
Then use send to call a symbol as a method name.


2022-09-30 21:44

<%=render'_shared/tag_list', tag_list:origque_content.grammar_list, path::prepque_origques_path%>

and

<%=link_to tag, send(path,tag_name:tag,order:params[:order])%>

I was able to give it to you in


2022-09-30 21:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.