Ask A Question

Notifications

Youโ€™re not receiving notifications from this thread.

Form with references field

Christian Herber Santos asked in Rails

I have a form with references field:

<%= form.label :name, style: "display: block" %>
<%= form.text_field :name %>

<%= form.label :city_id_id, style: "display: block" %>
<% cities_array = City.all.map { |city| [city.name, city.id] } %>
<%= select_tag :cities_array, options_for_select(cities_array) %>

But this error is showing after send form:

ActiveRecord::StatementInvalid in EntitiesController#create
SQLite3::SQLException: no such table: main.city_ids
Reply

Hey there,

The error you're encountering, "SQLite3::SQLException: no such table: main.city_ids," suggests that there might be an issue with the database table name. Check if you're referencing the correct table name, which should be "cities" instead of "city_ids" in your code. Double-check your database schema and table names to make sure they match. ๐Ÿ› ๏ธ๐Ÿ—„๏ธ๐Ÿ”

Reply

Hello,

Yes, I checked the database and saw that my error was when I generated the model, putting the city_id:references field instead of just city:references.

Thanks

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.