مساعدة مع وحدة التحكم في Rails لتحرير قالب النص

I’d like to edit directly in rails a text template, say user_notifications.user_watching_first_post.text_body_template.

Can someone please help point me to the rails console commands for this? I’m not rails savvy and couldn’t find the object that holds those.

إعجاب واحد (1)

(I don’t know how to do that offhand). What problem is that solving? Why not do it from the UX or the API?

إعجاب واحد (1)

Related to his other topic: 3.2.x still ignores some custom email templates.

It seems template modifications are ignored.

Are you sure you edit for the wanted language?

إعجاب واحد (1)

Yes, though it’s more related to this issue

The GUI for templates is very buggy so I’d like to solve it somehow

إعجاب واحد (1)

Without looking carefully at the code, I’m 99% sure that the issue is on the Rails side and not the UX side, so I don’t think changing it on the Rails side is likely to fix anything. If you have a budget, I can help figure out how to do what you ask, but won’t promise that it will solve your problem.

You can find ones you’ve changed with something like this:

TranslationOverride.all.pluck(:id, :translation_key)

And then update them with something like

to=TranslationOverride.find(1)
to.value="My new value for the override"
to.save

I don’t promise that this will work or not make things worse. But worse case you should be able to un-do your changes from the UX.

I don’t think the issue is on the rails side, since the UI wrongly lists the allowed tags (so that list is wrongly hardcoded somewhere) but %{base_url} is parsed just fine otherwise (see the thread), i.e. with rails i should be able to force save the value (bypassing any checks).

But all this is offtopic, really: my original question was just for a pointer on what rails object to target. If you can only offer paid help then I’ll wait hoping someone else is willing to offer some free help (I did that in other threads, also some github PRs). No hard feelings :slight_smile:

Edit: You edited your post while I was typing. I’ll see how far I get with what you suggested (not sure how to adapt that for my specific example yet). TranslationOverride might be enough of a pointer

إعجاب واحد (1)

It was enough of a pointer, and I also found the bug (which is in the ruby code):

to=TranslationOverride.where(translation_key:"user_notifications.user_watching_category_or_tag.text_body_template").first
to.value="%{username} posted in \"[%{topic_title}](%{base_url}%{url})\"\n\n--"
to.save!
ActiveRecord::RecordInvalid: Validation failed: The following interpolation key is invalid: base_url
from /var/www/discourse/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8/lib/active_record/validations.rb:80:in `raise_validation_error'

validations.rb is the culprit … base_url is valid, and does get parsed just fine (as I explained in the linked thread). It seems I either need to hack validations.rb (ugh!) or edit the SQL database directly (which is what I had after the upgrade) … so now I need to find where in the postgre database these template tags live :frowning:

p.s. It’s such an easy and quick fix though for the devs (I could do a PR but I only know a subset of tags where %{base_url} is missing from the valid tags)

إعجاب واحد (1)

Actually:

to.save(validate: false)

… did work just fine.

Edit: The GUI doesn’t show it immediately (I guess sidekiq caching). I did a ./launcher restart app for that.

For completion:

to=TranslationOverride.where(translation_key:"user_notifications.user_watching_category_or_tag.text_body_template").first
to.value="%{username} posted in \"[%{topic_title}](%{base_url}%{url})\"\n\n--"
to.save(validate: false)
إعجابَين (2)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.