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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:22:13+00:00 2026-05-18T05:22:13+00:00

My Project Model looks like this: # == Schema Information # Schema version: 20101117094659

  • 0

My Project Model looks like this:

# == Schema Information
# Schema version: 20101117094659
#
# Table name: projects
#
#  id          :integer         not null, primary key
#  name        :string(255)
#  description :string(255)
#  designer_id :integer
#  client_id   :integer
#  notified    :boolean
#  created_at  :datetime
#  updated_at  :datetime
#  user_id     :integer
#

class Project < ActiveRecord::Base

  belongs_to :user
  has_many :stages
  has_many :uploads
  has_many :comments

end

The Projects Controller looks like this:

class ProjectsController < ApplicationController
  filter_resource_access

  # GET /projects
  # GET /projects.xml
  def index
    @projects = Project.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @projects }
    end
  end

  # GET /projects/1
  # GET /projects/1.xml
  def show
    @project = Project.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @project }
    end
  end

  # GET /projects/new
  # GET /projects/new.xml
  def new
    @project = Project.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @project }
    end
  end

  # GET /projects/1/edit
  def edit
    @project = Project.find(params[:id])     
  end

  # POST /projects
  # POST /projects.xml
  def create
    @project = Project.new(params[:project])

    respond_to do |format|
      if @project.save
        format.html { redirect_to(@project, :notice => 'Project was successfully created.') }
        format.xml  { render :xml => @project, :status => :created, :location => @project }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @project.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /projects/1
  # PUT /projects/1.xml
  def update
    @project = Project.find(params[:id])

    respond_to do |format|
      if @project.update_attributes(params[:project])
        format.html { redirect_to(@project, :notice => 'Project was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @project.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /projects/1
  # DELETE /projects/1.xml
  def destroy
    @project = Project.find(params[:id])    
    @project.destroy

    respond_to do |format|
      format.html { redirect_to(projects_url) }
      format.xml  { head :ok }
    end
  end
end

When a user logs in, and goes to clicks ‘View all projects’ which links to the index action of the projects controller, I want them to only see the projects that they are allowed to see.

The index view of the projects controller looks like this:

<h1>Listing projects</h1>

<table>
  <tr>
    <th>Name</th>
    <th>Description</th>
    <th></th>
  </tr>

<% @projects.each do |project| %>
    <tr>
        <td><%= link_to project.name, project %> | </td>
        <td><%= project.description %> | </td>


        <% if permitted_to? :edit, @project %>
            <td><%= link_to 'Edit', edit_project_path(project) %></td>
        <% end %>

        <% if permitted_to? :destroy, @project %>
            <td><%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %></td>
        <% end %>
    </tr>
<% end %>
</table>

<br />

<% if permitted_to? :create, Project.new %>
    <%= link_to 'New Project', new_project_path %>
<% end %>

I don’t want you to do this for me, but could you walk through with me what I would need to do. i.e. do I need to add new columns to the tables, or do I create a new table and create a join between that new table and my users and projects model & tables?

Another thing to keep in mind, I have four major models that I want personalized to each user. Projects, comments, uploads, stages.

Oh, and I have a superuser that I want to be able to view all projects/comments/stages/uploads per user (both on a granular level, and on a high-level).

Would love to hear your thoughts.

Edit: Also, if you could possibly point me in the direction of some reading material that might help me with this entire process – I would really appreciate that.

  • 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-18T05:22:13+00:00Added an answer on May 18, 2026 at 5:22 am

    You need to add in your User model :

    class User
      ...
      has_many :projects
    end
    

    And this should to the trick :

    @projects = current_user.projects
    

    It will work if you have a current_user method of course. Otherwise it’s equivalent to (although I’m sure you don’t want to pass the user_id) :

    @projects = User.find(params[:id]).projects
    

    You should really read the rails tutorial book or the rails guides

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

Sidebar

Related Questions

If i have a sq-table relation model that looks like this: Project <----> ProjectActivity
I've created a simple Project model with four attributes: Project name:string description:text complete:boolean user_id:integer
I have a model that looks like this: class ProjectImage(models.Model): big_thumb = ThumbnailField(upload_to='profiles', size=(500,
Let's say that you have a Model that looks kind of like this: public
I've got a table that looks like this: Foo FooId : int (PK) BarId
Consider this simple model, where a Project has one ProjectType and, naturally many Projects
I have this Project model: class Project < ActiveRecord::Base validates :status, :inclusion => {
class Project(models.Model): categories = models.ManyToManyField(Category) class Category(models.Model): name = models.CharField() now, i make some
Given the following model: class Project(models.Model): project_name = models.CharField(max_length=255) abstract = models.TextField(blank=True, null=True) full_description
I have a Project model. This model has Days which are inlines . How

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.