Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How to get param values through radio_buttons ?

General • Asked by rodolfo

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-#{}", class:'custom-control-input' %>
            <label class="custom-control-label" for="responsible-manage-<%= %>">
                <div class="d-flex align-items-center">
                    <%= image_tag user_avatar(, 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>
        <% end %>

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?

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 ,, id:"responsible-manage-#{}", class:'custom-control-input' %>

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

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.