Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:04:30+00:00 2026-06-04T20:04:30+00:00

So I am a beginner in ROR, like I know it for a month

  • 0

So I am a beginner in ROR, like I know it for a month (school assignment and we don’t get a cursus we need to use ‘google’)

So I want a dropdown box with a list of all my cities. Then if I pick a city I need to save the city_id in my database together with the date. The code I have so far seem to work except when I click on save it says that city is empty (and it can’t be empty because of the failsave)

this is my code

    <div class="field">
    <%= f.label :stad_id %><br />
    <% cities_array = Stad.all.map { |stad| [stad.naam, stad.land] } %>
    <%= select_tag(Stad, options_for_select(cities_array))  %>


    </div>
  <div class="field">
    <%= f.label :datum %><br />
    <% datum = Time.now.to_s(:db) %>
    <%= f.text_field :datum, :value => datum.inspect, :readonly => true %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

I don’t really know what I am doing wrong except I have an eery feeling I don’t actually give the command to save it.

help is much thanked
sincerely
Robin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:04:31+00:00Added an answer on June 4, 2026 at 8:04 pm

    There are a few things I notice here that are wrong.

    1) Put the creation of the cities_array into your controller, not in your view:

    def edit
      @something = Something.find(params[:id])
      @cities_array = ... whatever ...
    end
    

    2) When creating your cities_array, you need to specify the ID of the city as the second parameter, like this:

    @cities_array = Stad.all.map { |stad| [stad.naam, stad.id] }
    

    3) The select_tag call isn’t for Stad, it’s for the model you’re trying to save. For example, your form might look like this:

    <%= form_for @something %>
      <%= f.label :city %>
      <%= f.select :city_id, @cities_array %>
      # or!
      <%= select :something, :city_id, @cities_array %>
    <% end %>
    

    I hoep this clears things up for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner question -- what do you usually use as a multimap? I want a
I am a beginner ROR web developer, I have google charts running on my
Absolute beginner question: I have a template file index.html that looks like this: ...
(R beginner here...) I have a dataset like: > head(q) Date Time System User
I'm a RoR beginner, and I have a problem with my app. I have
Hi this is ROR beginner's question. I have creat controller.rb and view hello.rhtml following
(Beginner to HTML) I have made a Photoshop mock-up of the website I want
I know this is a minor issue, but why, if you use scaffolding in
I'm a complete programming beginner. I know a little HTML and the only CSS
I am complete beginner to CakePHP but I am a bit knowledgeable in ROR.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.