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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:30:29+00:00 2026-05-27T07:30:29+00:00

I am currently working on a web app for social networking site but it

  • 0

I am currently working on a web app for social networking site but it seems as if getting my nested resources to work correctly is impossible. If you can help me out that would be great and I would be very thankful.

Here are my routes. I would like to have the url structure like mysite.com/username/photos /(new, edit, etc). The url structure is like so but I get an error when trying to access the forms or page. Down below I have posted what I have so far.

routes.rb

   resources :users do  
   resources :photos  
   end 

photo.rb

belongs_to :users

user.rb

has_many :photos, :foreign_key => "id", :dependent => :destroy

_form.html.erb
This form has an attachment using paperclip. There is a <% before statement I removed it because it would not show the entire code below on here.

 form_for(@photos,@user) :html => {:multipart => true} do |f| %>

photos_controller.rb

 def new
  @photo = Photo.new(params[:photo])
 end
  • 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-27T07:30:30+00:00Added an answer on May 27, 2026 at 7:30 am

    You need to create a before_filter to get the user, and the form posts to create, not new. Your photo controller should look something like:

    before_filter :get_user
    ...
    
    def new
      @photo = @user.photos.build
    end
    
    def create
      @photo = @user.photos.build(params[:photo])
      respond_to do |format|
        if @photo.save
          format.html {redirect_to [@user, @photo], notice: "Photo saved!"}
        else
          format.html {render action: "new"}
        end
      end
    end
    ...
    private
    def get_user
      @user = User.find(params[:user_id])
    end
    

    Here, the before_filter grabs the user. In nested routes, the parent resource ID will be in params[:parent_id] or in this case, params[:user_id]. Then inside the create controller, you want to build a photo from the @user.photos collection. This will automatically create the reference between the photo and the user.

    Also, your form_for has the relations backwards. It should be form_for([@user, @photo]) ..., not the other way around.

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

Sidebar

Related Questions

The ASP.NET web app project I'm currently working on is getting slower over time
I am currently working on a web app using Wicket and started using jQuery
I am currently working on a web-app/server in python and cherrypy. Right now, I
I'm currently working on building a java web app. I've been looking to use
I’m currently working on a small web app that allows people to search for
I currently started working on a maven web-app project that needs to be launched
I am currently working on a simple web application through Google App engine using
In the web app that I'm currently working on I've to make multiple calls
the web app I am currently working on generates a PDF file and sends
I'm currently working on a web site which involves a data upload process. The

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.