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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:28:10+00:00 2026-06-05T15:28:10+00:00

I’m writing a rails app that has a model called ‘User’ and a model

  • 0

I’m writing a rails app that has a model called ‘User’ and a model called ‘Page’. Users can have multiple pages, and users can also authorize other users to view their pages. To describe this in rails, I’m using a has_many, :through relationship with a third model I’ve created called ‘Authorization’. The models look something like this:

class User
  has_many :pages, dependent: :destroy
  has_many :authorizations, dependent: :destroy
  has_many :viewable_pages, :through => :authorizations, :source => 'page'
end

class Page
  belongs_to :user

  has_many :authorizations, dependent: :destroy
  has_many :authorized_viewers, :through => :authorizations, :source => 'user'
end

class Authorization
  belongs_to :page
  belongs_to :user
end

As far as back-end functionality goes, this has been working perfectly for me. I’m a little stumped when it comes to rendering these relationships and allowing the client to modify them.

I have a controller for Page, and when ‘show’ is called, I render the page. When I render the page, I also want to render the page’s list of authorized_viewers and allow the user to modify that list with AJAX commands. Essentially, I want to do something like this in the ‘Page’ layout:

<% @authorized_viewers.each do |v| %>
  <li><%= v.email %><%= link_to 'delete', authorization, method: :delete, remote: :true %></li>
<% end %>

I’m not quite sure how to reference the authorization itself, and not the authorized_viewer. I just want to delete the relationship, not the user. I’m also not sure if I should make a controller for ‘Authorization’ in order to create methods like ‘destroy’, which I can modify and give them the ability to respond to AJAX calls. Authorizations will only be rendered on the ‘Page’ view, so it doesn’t seem to make sense generate a whole scaffold with views for Authorizations. What’s the best way to approach this?

I realize this is a very long question. Any insight would be tremendously appreciated!

  • 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-06-05T15:28:11+00:00Added an answer on June 5, 2026 at 3:28 pm

    An easier way to show the authorizations in the view would be (assuming you are using nested routes for the page/authorization relationship, modify the path argument otherwise):

    <% @authorizations.each do |authorization| %>
      <li><%= authorization.user.email %><%= link_to 'delete', page_authorization_path(@page, authorization), method: :delete, remote: :true % </li>
    <% end %>
    

    It would be best to create a controller for authorizations if you are going to be performing actions directly against that object (such as create/destroy). You don’t have to create any views if this is always going to be done over AJAX. This keeps all of your functionality organized, and will ensure that any interactions relating specifically to authorizations reside in the authorizations controller. Avoid creating a scaffold, instead just create the controller with two actions: create and destroy

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.