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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:03:27+00:00 2026-05-24T14:03:27+00:00

I am trying to write the edit/update methods for one of my forms. The

  • 0

I am trying to write the edit/update methods for one of my forms. The only time this model needs to be changed is to go from an ‘inactive state’ to an ‘active state.’ I would like to do this with a button, but I cannot figure out how to make it work. My form with the button looks this:

<% form_for [league, league_relation], :html => {:method => :put} do |form| %>
<%= form.error_messages %>
  <fieldset>
    <%= form.hidden_field :state, LeagueRelation::ACTIVE %>
    <%= form.submit 'Activate User' %>
  </fieldset>
<% end %>

This form is to update my LeagueRelation model, which is a nested resource of the League model. The default state is 1, which means inactive. Here, I am trying to create a form with only one button that says Activate. Since this is a form builder, Rails is trying to put the value of league_relation.state into the hidden field, instead of the value I want. I know using hidden_field_tag would work, but I do not want to use this approach. Any suggestions?

Thanks

  • 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-24T14:03:27+00:00Added an answer on May 24, 2026 at 2:03 pm

    In this case I would probably use the button_to helper instead of form_for. Perhaps something like this:

    button_to "Activate User", 
              :url => path_to_update_url, 
              :method => :put, 
              :state => LeagueRelation::ACTIVE
    

    The button_to helper will automatically create a button wrapped inside a form with all the parameters that you choose to supply.

    Edit:

    Though if you still want to use the form_for then you can manually specify a value like this:

    <%= form.hidden_field :state, :value => LeagueRelation::ACTIVE %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Edit: randrange is just random.randrange, I didn't write my own RNG) I'm trying to
im trying to write an app that will display a list off lines from
I'm trying to write a method that interpolates from 0 to x (position of
I am trying to copy an SPListItem (with file) from one site collection to
I'm new to linq and I'm trying to write an update statement. I have
I'm trying to update a table based upon the user id from another table.
I'm trying write a query to find records which don't have a matching record
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
Trying to write a couple of functions that will encrypt or decrypt a file
Im trying to write a single byte at a certain location in a file.

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.