Answer the question
In order to leave comments, you need to log in
How to make an in-text-tag on a resource in Rails?
Just like in the toaster, you can mention any user by @user_name and then you can follow the link to his profile, you want to do the same for another resource in the application.
I would like to achieve the following, when generating html code with tag markup, the code replaces the tag with route_path (resource), which is available in the controller.
Tell me the solution?
Answer the question
In order to leave comments, you need to log in
I would try to solve the problem using helper. Find a tagged word (for example, @username) with a regular and substitute route_path(resource)
helper:
module PostsHelper
def in_text_tag(s)
...тут действия над s...
end
end
module ApplicationHelper
def in_text_tag(s)
s.sub(/(@\d*)/) {
|i| User.where(phonenumber: i.gsub(/@/, '')).first.name
}
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question