Do topic custom fields add a column to the topics model? I am getting an error saying no, and I’m trying to figure out what to do about it.
I have created a topic custom field in development, following here. Let’s call it fun_level
. The custom field seems to be successfully created in development, bc if I do an ajax call to get back a topic I have created after adding the custom field–like ajax("/t/112.json")
–it works: the topic data comes back showing the field fun_level
with the value I entered.
But now I need to find a way to programmatically retrieve all topics with a certain value for the custom field (eg, get a list of all topics where fun_level
= ‘super-duper-fun’).
I’ve considered doing an ajax("/search")
for that, but I haven’t gotten it to work yet.
Another method I thought of was to use classic rails: create a controller, and when I go to a certain path (/fun_levels/:fun_level), call the following show method:
def show
respond_to do |format|
format.json { render json: Topic.where(fun_level: 'super-duper-fun') }
end
end
Then, I call ajax("/fun_levels/super-duper-fun.json")
…
This controller show method/ajax call
strategy works if I am finding topics based on an id, title, etc. But when I use the above code-Topic.where(fun_level: 'super-duper-fun)
–it sends an internal server error
. And the logs say:
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column topics.fun_level does not exist LINE 1: ... "topics" WHERE "topics"."deleted_at" IS NULL AND "topics"."...
Is there a way to get back topics based on a custom field using a controller method, like I’ve provided above? (like my: { render json: Topic.where(fun_level: 'super-duper-fun') }
)