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 708047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:20:48+00:00 2026-05-14T04:20:48+00:00

I feel like this might be really simple but I’m just not getting it

  • 0

I feel like this might be really simple but I’m just not getting it right, so I have like a settings page in my app and I want each setting to be like a key value store, for example:

+-------------------+--------------------------------+
| setting           | value                          |
+-------------------+--------------------------------+
| twitter_username  | something                      |
+-------------------+--------------------------------+
| facebook_url      | http://facebook.com/someguy    |
+-------------------+--------------------------------+

My form looks something like this:

<% form_tag set_admin_settings_path, :method => :put do %>
  <ol>
  <% for setting in @settings %>
    <li class="field">
      <label><%= setting.setting_name.humanize %></label>
      <%= text_field_tag "[setting_value][]", setting.setting_value %>
    </li>
  <% end %>  
    <li class="submit">
      <%= submit_tag "Update settings" %>
    </li>
  </ol>

<% end %>

Everything renders fine but when I try to save the form, nothing is saved 🙁

  • 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-05-14T04:20:48+00:00Added an answer on May 14, 2026 at 4:20 am

    This is how I think it should look, I’ve modified your form a bit. This also assumes you’re not doing any validation on the setting objects, validation and displaying errors would be tricky with multiple instances of the Setting class in a single form, but it could be done. My example will not display any errors.

    config/routes.rb

      map.namespace(:admin) do |admin|
        admin.resources :settings, :collection => { :set => :put }
      end
    

    app/controllers/admin/settings_controller.rb

    def set
      #this is what I think your action should do
      params[:settings].each do |setting|
        @setting = Setting.find(setting[:id])
        @setting.update_attributes(setting)
      end
    
      redirect_to admin_settings_path
    end
    

    app/views/admin/settings/index.html.erb

    <% form_tag set_admin_settings_path, :method => :put do %>
      <ol>
      <% for setting in @settings %>
        <li class="field">
          <label>
            <%= setting.setting_name.humanize %>
          </label>
          <!-- settings[][field_name] will group the settings objects in params -->
          <%= hidden_field_tag("setting_#{setting.id}_id", 
                               setting.id,
                               :name => 'settings[][id]') %>
          <%= text_field_tag("setting_#{setting.id}_setting_value", 
                             setting.setting_value,
                             :name => 'settings[][setting_value]) %>
        </li>
      <% end %>  
        <li class="submit">
          <%= submit_tag "Update settings" %>
        </li>
      </ol>
    
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like the answer to this question is really simple, but I really
I feel like a bit of a newbie posting this, but anyway: I have
I feel like this is a dumb question and I'm missing something, but I
I feel like I should know this, but I haven't been able to figure
I'm sorry, but this is beginning to feel like kicking myself in the head.
This is very simple, but I'm being rather stupid about it. I have a
Feel like this should be something easy that I'm missing. I have a table
This seems like a bug in Rails to me, but there's probably not much
I feel like I've been all over the web for this but haven't found
This might seem like a silly question, but after asking some questions on stackoverflow

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.