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

  • Home
  • SEARCH
  • 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 6232669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:09:23+00:00 2026-05-24T10:09:23+00:00

Spoiler alert: this is a stupid question ;) I have a Rails form where

  • 0

Spoiler alert: this is a stupid question 😉

I have a Rails form where I display avatar images for the user to select, fetched from the services associated with the user account via Omniauth. It looks like this and it renders without any issues:

<%= form_for @user, :remote => true do |f| %>
  <% @services.each do |service| %>
    <% if service.avatar == @user.avatar %>
      <%= link_to image_tag(service.avatar), '#', :size => "48x48", :id => "current_avatar" %>
    <% else %>
      <%= f.text_field :avatar, :value => service.avatar, :type => :hidden, :class => "clickable"%>
      <%= image_tag(service.avatar, :class => "clickable") %>
    <% end %>
  <% end %>
<% end %>

The relevant part of my application.js file looks like this:

$('.clickable').live('click', function() {
  $(this).parents('form:first').submit();
});

The jquery-rails gem is installed and working ok.

The issue is that this setup obviously submits the whole form, making the user avatar be the last one on the list, no matter which one the user clicks.

Is it possible to submit only the field associated with the image clicked by the user?

I have a good understanding of Rails but JQuery is completely new to me, so I’m really lost. Googled a lot and couldn’t find anything. At least nothing that I could understand 😉

  • 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-24T10:09:24+00:00Added an answer on May 24, 2026 at 10:09 am

    Why are you using hidden text fields for this? I think radio buttons would serve you better. Just create one radio button per avatar (with the current selection checked by default), make sure they all have the same name, and then wrap the image_tag elements in <label>s so that people can click on something. The values for the radio buttons would be the same :value => service.avatar that you’re using for the text fields.

    Once that’s in place, you can submit away and it’s all good as the form will only return one of the avatars.

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

Sidebar

Related Questions

Spoiler alert: this is related to Problem 14 from Project Euler. The following code
Spoiler alert: Maybe a stupid question. :) #include <iostream> using namespace std; class Base
UPDATE (spoiler): This question is answered (see David Carlisle answere below) and it looks
Spoiler: It was an outdated version of the rspec-rails gem! I encountered this error
Note that this question contains some spoilers. A solution for problem #12 states that
I have come to Java from Visual Basic, and seem to think I have
Possible Spoiler Warning I've spent ages trying to improve this algorithm and work out
There is another recent Project Euler question but I think this is a bit
Spoiler: I am an absolute beginner to C. I quickly threw threw together this
spoiler : This is just another Lucene vs Sphinx vs whatever, I saw that

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.