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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:25:57+00:00 2026-05-17T17:25:57+00:00

could really use your help, understanding this complex rails issue I’ve been banging by

  • 0

could really use your help, understanding this complex rails issue I’ve been banging by head against the wall on…

I have the following Models:

Permissions (user_id, role_id, project_id) 
Roles (id, name) 
Projects (id, name)

Permissions is the Y model for Roles and Projects.

I’m struggling to make a form to allow a user to either Add or Update a User’s Project permission

In the controller I have:

@project = Space.find(params[:project_id])
@permission = @project.permissions.find_by_user_id(params[:user_id])

And then in the view:

<%=form_for [:space, @permission] do |f| %>....

But this isn’t working, errors:

  • If the criteria of (user & project) don’t have any records in the DB: “undefined method `model_name’ for NilClass:Class”

  • If there is a record in the DB, meaning the user does have a role on this project: "No route matches {:action=>"destroy", :controller=>"permissions", :project_id=>#<Permission project_id: 3, role_id: 2, user_id: 13>}"

Ideally, I want this form to show the current permission if any for the given (Used/Project)… If there isn’t a current permission, I want the person to be able to create a record.

Anyone experiences around this type of relationship in Rails 3? Thank you for any tips you can send my way.

Routes file (the part that’s specific to these models)

resources :projects do
  resources :photos, :permissions
    collection do
        get 'yourcurrentprojects'
    end
end

Controllers
– Path where users are giving the option to CRUD a permission: /projects/3/permissions
– I believe I’d want to use Permissions.rb def Show and def Update to get and set permissions?

  • 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-17T17:25:57+00:00Added an answer on May 17, 2026 at 5:25 pm

    For the first error where you have a nil object you should pass in a blank object wherever you’re passing objects to forms eg @permission ||= @project.permissions.new (assuming it’s the permission object that is causing the nil object. Or to be fancier @project.permissions.find_or_initialize_by_user_id(params[:user_id]).

    For the second error, It’s odd that it’s trying to map to destroy, it should be trying to map to the :update action right? run rake routes to see all routes in the application to verify that the PUT /projects/:project_id/permissions/:id action exists and maps to permissions#update

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

Sidebar

Related Questions

No related questions found

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.