0

I'm building a small business app. There's a Sales table and Cars and Clients tables that are referenced by it with (car_id, client_id)

Now in the view where I create a Sale you can select an existing car and client from dropdowns. These don't display the actual objects but a property of that the capacity for cars and name for clients.

How do you deal with the initial nonexistence of the objects. If the user hasn't created a car or client, setting the dropdowns to display client.name and car.capacity results in an exception (nil doesn't have the method name or capacity)

It works after you start adding clients or cars but produces an error until that point.

1 Answer 1

1

Without seeing any code, you can use something like:

<% if @cars.empty? %>
# do something
<% else %>
# show dropdowns etc.
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.