Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to get param values through radio_buttons ?

rodolfo asked in General

I'm trying to create a TARGET with a responsible user via form_with:

<div class="form-group-users">
    <% @users.each do |user| %>
        <div class="custom-control custom-radio">
            <%= f.radio_button :responsible_id ,'', id:"responsible-manage-#{user.id}", class:'custom-control-input' %>
            <label class="custom-control-label" for="responsible-manage-<%= user.id %>">
                <div class="d-flex align-items-center">
                    <%= image_tag user_avatar(user.id), class:'avatar mr-2', 'data-title' => user.first_name , 'data-toggle':'tooltip' %>
                    <span class="h6 mb-0" data-filter-by="text"><%= user.first_name %> <%= user.last_name %></span>
                </div>
            </label>
        </div>
        <% end %>
    </div>

The problem here is that params for responsible_id is empty.

Parameters: {"utf8"=>"✓", "authenticity_token"=>"+gh9H09zXkp+W0cUeZO12HDPgWHqWWcVsW+XxD/8o68srfQt/Od0MH/kYNYe6KxQZ2ncFDVq3v5RK267NEPEYw==", "target"=>{"title"=>"Target 2", "description"=>"", "due_date"=>"2018-12-31", "responsible_id"=>"", "team_id"=>""}, "visibility"=>"on", "commit"=>"Create"}

Any ideas?

Reply

Hey rodolfo,

You need to add the value you want passed for each radio button. If you check out the docs, you'll see the structure is: radio_button(method, tag_value, options = {})

So your tag should look like this:

<%= f.radio_button :responsible_id , client.id, id:"responsible-manage-#{user.id}", class:'custom-control-input' %>
Reply

Awesome! Thank you @jacob. I love this community.

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 73,895+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.