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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:27:48+00:00 2026-05-27T03:27:48+00:00

I’ve searched my problem high and low on here and haven’t quite found the

  • 0

I’ve searched my problem high and low on here and haven’t quite found the right answer. I think it might be a simple routes issue. On my app, a user can create a project and follow “plants” through their project before ever having to officially sign up. The routes for updating and editing the project itself work fine. The error I get “couldn’t find Project without an ID” only occurs after I try accessing the CREATE action in my “Prelationships” controller to build a relationship between the “Project” and the “Plants.” My code is below:

My routes.rb

resources :sessions,       :only => [:new, :create, :destroy]
resources :microposts,     :only => [:create, :destroy]
resources :relationships,  :only => [:create, :destroy]  
resources :prelationships, :only => [:create]
resources :plants   
resources :projects do        
  member do
   get :pfollowing, :pfollowers  
  end
end       

My “Prelationships” controller

class PrelationshipsController < ApplicationController

  def create   
    @project = Project.find(params[:project_id])                                   
    @plant = Plant.find(params[:prelationship][:pfollowed_id])
    @project.pfollow!(@plant)
    respond_to do |format|
      format.html { redirect_to @project }
      format.js { redirect_to @project }
    end
  end
end

My “Prelationships” model

class Prelationship < ActiveRecord::Base                          
attr_accessible :pfollowed_id

belongs_to :pfollower, :class_name => "Project"
belongs_to :pfollowed, :class_name => "Plant"

validates :pfollower_id, :presence => true
validates :pfollowed_id, :presence => true
end                

My “Projects” model

class Project < ActiveRecord::Base                    
attr_accessible :title, :address, :latitude, :longitude, :state      

belongs_to :user        
has_many :prelationships, :foreign_key => "pfollower_id",
                        :dependent => :destroy   
has_many :pfollowing, :through => :prelationships, :source => :pfollowed          

  def pfollowing?(pfollowed)
    prelationships.find_by_pfollowed_id(pfollowed)  
  end  

  def pfollow!(pfollowed)
    prelationships.create!(:pfollowed_id => pfollowed.id)
  end
end    

My “Plants” model

class Plant < ActiveRecord::Base      

has_many :prelationships, :foreign_key => "pfollowed_id",
                        :class_name => "Prelationship"
has_many :pfollowers, :through => :reverse_prelationships, 
                    :source => :pfollower   
end

My partial for building the relationship on the @project ‘show’ page

<%= form_for @project.prelationships.build(:pfollowed_id =>
                                 @project_id) do |f| %>
<%= collection_select(:prelationship, :pfollower_id, Plant.all, :id, :name, options =   
{:prompt => "Select your plants"}, :class => "listselect") %>
<div class="actions">
<%= f.submit "Pfollow" %>
 </div>
<% end %>

The error message is “Could not find Project without an ID” once I hit submit on the partial.

app/controllers/prelationships_controller.rb:4:in `create'

and the Parameters:

{"utf8"=>"✓",
"authenticity_token"=>"NKqa1f0M2yPLQDHbRLnxl3SiwBeTus/1q1hpZjD7hgY=",
"prelationship"=>{"pfollower_id"=>"5"},"commit"=>"Pfollow"}  

If this is a routes issue, I can’t seem to find the right language to fix it. I’ve built a User model with the ability to follow other users and did not have these problems, which leads me to believe I might have to create a session for my project?

Help this newbie, please!

  • 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-27T03:27:50+00:00Added an answer on May 27, 2026 at 3:27 am

    The simple way:

    <%= form_for @project.prelationships.build(:pfollowed_id =>
                                 @project_id) do |f| %>
        <%= collection_select(:prelationship, :pfollower_id, Plant.all, :id, :name, options =   
        {:prompt => "Select your plants"}, :class => "listselect") %>
        <%= hidden_field_tag :project_id, @project.id %>
        <div class="actions">
            <%= f.submit "Pfollow" %>
        </div>
    <% end %>
    

    And the right way would be creating a nested route on projects, but you can do this refactoring as an exercise for later.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.