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

The Archive Base Latest Questions

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

I am uploading an image and want to associate it with the current project

  • 0

I am uploading an image and want to associate it with the current project I’m in. I’m inside a project at the URL example.com/projects/1 and render this form:

<%= semantic_form_for @image, :html => { :multipart => true } do |f|%>
  <%= f.semantic_errors %>
  <%= f.inputs do %>
    <%= f.input :title %>
    <%= f.input :description %>
    <%= f.input :image, :as => :file %>
  <% end %>
  <%= f.buttons do %>
    <%= f.commit_button :label => 'Upload Image', :button_html => { :class => "btn primary" } %>
  <% end %>
<% end %>

I’ve set in image.rb model, belongs_to :project and in project.rb model, has_many :images

My images_controller.rb create method looks like this:

def create
  image = params[:image]
  if user_signed_in?
    @image = Image.new(:title => image[:title],
                       :description => image[:description],
                       :user_id => current_user.id,
                       :project_id => params[:id])
  if @image.save
    flash[:success] = "Successfully uploaded an image"
    redirect_to project_path(params[:id]) and return
  else
    flash[:error] = "Error with image upload"
    redirect_to new_image_path and return
  end
 else
   redirect_to root_path
 end    
end

The image is created but fails to associate the image with the project_id. I know the problem is with params[:id] not pulling in the project_id, how do I pull the project id from the URL and associate it with the image?

  • 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-29T07:18:56+00:00Added an answer on May 29, 2026 at 7:18 am

    You should use your associations to create the new Image.

    @image = Project.find(params[:id]).images.create(:title => image[:title],
                       :description => image[:description],
                       :user => current_user)
    if @image.save...
    

    if that does not work, please post the contents of your routes.rb and the url that is hit from the post request.

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

Sidebar

Related Questions

I am uploading in image via a form and I want to, in addition
My user is uploading an image of any size XX x YY. I want
I am very new to grails.I am doing one sample project for image uploading
I want to show a different icon/image depending on an enum value. For example,
I am using Jquery form plugin. Popup is displayed with image uploading form. Image
I want to make a fancy image uploading system in html. When the user
I am uploading some image files using servelt. I want to resize the images.
I'm programatically uploading image files and want to set the filename. When I upload
How can restrict/ validate paperclip for uploading image with fixed dimentions. I want to
use PHP and MySQL. Want my website to have the feature of image uploading

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.