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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:21:44+00:00 2026-06-12T06:21:44+00:00

I have Users and each user sets a Goal. So a goal belongs_to a

  • 0

I have Users and each user sets a Goal. So a goal belongs_to a user and a user has_one: goal. I am trying to use form_for in the view to allow the user to set their goal up.

I figured it would be like microposts (which is straight from Hartl’s tutorial) just with singular instead of plural. I’ve looked at tutorials and questions on here for this issue and tried numerous different things and I just can’t get it working.

I got the form_for actually working and apparently pointing to the correct route, but I’m getting the below error and I have no clue what it means:

undefined method `stringify_keys’ for “Lose Weight”:String

GoalsController

class GoalsController < ApplicationController
before_filter :signed_in_user

def create
 @goal = current_user.build_goal(params[:goal])
 if @goal.save
    redirect_to @user
 end
end

def destroy
    @goal.destroy
end

def new
    Goal.new
end

end

Goal Model

class Goal < ActiveRecord::Base
attr_accessible :goal, :pounds, :distance, :lift_weight
belongs_to :user

validates :user_id, presence: true
end

User Model

class User < ActiveRecord::Base

 has_one :goal, :class_name => "Goal"

end

_goal_form (which is a modal on the Users#show)

    <div class="modal hide fade in" id="goal" >
      <%= form_for(@goal, :url => goal_path) do |f| %>
      <div class="modal-header">
       <%= render 'shared/error_messages', object: f.object %>   
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3>What's Your Health Goal This Month?</h3>
      </div>
        <div class="modal-body">
          <center>I want to <%= select(:goal, ['Lose Weight'], ['Exercise More'], ['Eat   Better']) %> </center>
        </div>
        <div class="modal-body">
          <center>I will lose  <%= select_tag(:pounds, options_for_select([['1', 1],   ['2', 1], ['3', 1], ['4', 1], ['5', 1], ['6', 1], ['7', 1], ['8', 1], ['9', 1], ['10', 1]])) %> lbs. this month!</center>
        </div>
        <div class="modal-footer" align="center">
           <a href="#" class="btn" data-dismiss="modal">Close</a>
           <%= f.submit "Set Goal", :class => "btn btn-primary" %>
        </div>
  <% end %>
</div>

Routes.rb

  resource  :goal,               only: [:create, :destroy, :new]
  • 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-12T06:21:45+00:00Added an answer on June 12, 2026 at 6:21 am

    I expect the stringify_keys error is down to the way you’ve listed your options in the goal field, they need to be grouped up to be treated as one argument.

    Along with using accepts_nested_attributes_for :goal as suggested by Dipak, you will want to have a nested form.

    form_for @user do |form|
      fields_for @goal do |fields|
        fields.select :goal, ['Lose Weight', 'Exercise More', 'Eat Better']
    

    The save action is now in the context of a user, so the attributes that come through will include a portion for the goal fields:

    user =>{goal_attributes => {:goal => 'Eat Better'}}
    

    You can save these attributes by updating the user:

    @user.update_attributes(params[:user])
    

    As an aside, your “new” action should be @goal = Goal.new, just creating a new goal does nothing, you need to assign it to a variable for it to make it to the page.

    Good luck!

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

Sidebar

Related Questions

I have 200 users each user will eventually have a reviewINFO table with certain
In my web application I will have users, each user will have albums, and
I am creating a web application that will have many users. Each user has
I have a table users with primary index userId . Currently, each user has
I have about 1 million data in users table. Now I want each user
I have multiple Users, each with a collection of Tasks. public class User {
I have two models - Tenant and User, each tenant will have_many users and
I have a number of users. Each user has a number of bets, made
I have 2 entities: User and Avatar . Each user can choice one avatar
I have a table with user items. Each user may have several types of

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.