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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:45:27+00:00 2026-06-02T12:45:27+00:00

We have a requirement where a user needs to select their avatar for their

  • 0

We have a requirement where a user needs to select their avatar for their profile. On the edit profile page, the user clicks on a Change Picture link which takes them to another page and gives them with two links to get their photo from facebook or gravatar. There is also a preview of the image shown on this page, as well as a save button. The controller for this page is AvatarsController. I have edit and update actions, as well as custom GET actions for facebook and gravatar, so that the route looks like avatar/facebook, and avatar/gravatar. These actions simply query the respective services and create a new avatar model containing the url for the photo. When the user clicks save, the update action is called and the avatar model is saved with the profile. The page is delivered by the edit template, as by default, when a user is created, an empty avatar is also created.

The Profile model (using mongoid) essentially looks like:

def Profile
  embeds_one :avatar
end

and the avatar model looks like:

def Avatar
  embedded_in :profile
end

The route looks like:

resource :avatar, only: [:edit, :update] do
   member do
     get 'facebook'
     get 'gravatar'
   end
end

The controller looks like:

class AvatarsController < ApplicationController
  def facebook
    url = AvatarServices.facebook(current_user, params[:code])
    respond_to do |format|
      unless url
        format.json { head :no_content }
      else
        @avatar = Avatar.new({:url => url, :source => "Facebook"})
        @avatar.member_profile = current_user.member_profile
        format.html { render :edit }
        format.json { render json: @avatar }
      end
    end
  end
  def gravatar
    respond_to do |format|
      url = AvatarServices.gravatar(current_user)
      unless url 
        format.json { head :no_content }
      else
        @avatar = Avatar.new({:url => url, :source => "Gravatar"})
        @avatar.member_profile = current_user.member_profile
        format.html { render :edit }
        format.json { render json: @avatar }
      end
    end
  end
  def edit
    @avatar = current_user.member_profile.avatar
  end
  def update
    @avatar = current_user.member_profile.avatar
    respond_to do |format|
      if @avatar.update_attributes(params[:avatar]) 
        format.html { redirect_to edit_member_profile_path }
        format.json { head :no_content }
      else
        format.html
        format.json { render json: @avatar.errors }
      end
    end
  end
end

This works, but being fairly new to rails, I’m wondering if rails experts would have set up the ‘facebook’ and ‘gravatar’ resources differently, perhaps in a more RESTful manner?

  • 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-02T12:45:35+00:00Added an answer on June 2, 2026 at 12:45 pm

    Well, the subfolder is putting the facebook and gravatar controllers into a common namespace. You could use nested routes,

    resource :avatar, only: [:edit, :update] do
      resource :facebook
      resource :gravatar
    end
    

    This will route to a FacebooksController and a GravatarsController.

    This is kind of what you were thinking anyway, and you won’t need a record id for a facebook or gravatar record.

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

Sidebar

Related Questions

I have a requirement that when the user clicks on [X] button of the
I have a requirement wherein I need to display on a User form, a
I have the following requirement: Based on some user input, I need to generate
I have a requirement that a user is allowed only to enter string value
I have a requirement where I ask user for confirmation and also display messages.
I have a requirement in my MVC application to present the user with a
I have the fllowing requirement, I have a model called Task to display user
I have a project where the requirements is that a end user will select
I have a fairly simple requirement for a query API which I need to
I have a User table, which is having Userid(primary key), Username, Password There is

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.