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

The Archive Base Latest Questions

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

Newbie question, you’ve been warned! I’m trying to implement a sample Rails app with

  • 0

Newbie question, you’ve been warned!

I’m trying to implement a sample Rails app with a many-to-many association, people owning movies, and I’m trying to figure out how exactly to implement the UI for it. It’s my understanding that REST requires everything to be a resource, so in this case “User” (person), “Movie” and “Possession” (the joint table) (oh, the puns).

Now the interesting part, the UX. Let’s say I have a user dashboard where all of your movies are listed.

Let’s say the user wants to add a movie that he owns. How do you do this in REST? It’s trivial with a custom action that one could add to the User controller, but the point is not to go beyond the basic 7 REST actions, right? Therefore I’d have to first do a “new” on a movie and then do a “new” on a possession, which are two operations. How do I collapse them into one?

Basically I feel I’m not quite understanding how to maintain REST as soon as multiple models are involved and would appreciate a tip.

Thanks!

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

    Happily, Rails has some magic just for this common scenario. Assuming a model like this:

    class Movie
      has_many :users, :through => :possessions
    end
    

    Your view:

    <%= form_for [current_user, Movie.new] do |f| %>
      <%= f.label       :title %>
      <%= f.text_field  :title %>
    <% end %>
    

    Basically this form will POST to MoviesController#create and will pass along current_user.id as a user_id parameter that (the default) MoviesController#create will know to associate with the Movie it creates. Take a look at the documentation for FormBuilder#form_for for more information.

    You could also do this the other way around, by the way:

    class User
      has_many :movies, :through => :possessions
    
      accepts_nested_attributes_for :movies # magic!
    end
    

    And the view:

    <%= form_for current_user |user_form| %>
      <%= user_form.fields_for current_user.movies.build |movie_fields| %>
        <%= movie_fields.label      :title %>
        <%= movie_fields.text_field :title %>
      <% end %>
    <% end %>
    

    In this case the form will submit to UsersController#update and its parameters will look like this:

    { :id => 123,
      :movie => {
        :title => "The Red Balloon"
      }
    }
    

    …and the controller will know to create the Movie object. For more information check the documentation for FormHelper#fields_for.

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

Sidebar

Related Questions

Newbie question, beware! I'd like to implement a basic many-to-many relationship in Rails and
Newbie question. I’m writing an ASP.Net MVC app in VB.Net and have been using
Newbie question on Rails 3 development. I am creating my first app and planning
Newbie question since I'm not up to speed using maven at all. I'm trying
Total newbie question but this is driving me mad! I'm trying this: myInt =
Super-newbie question! I've been looking for a list of all the classes that come
Newbie question. After I have written the Android App (easy part) I need to
Django newbie question.... I'm trying to write a search form and maintain the state
A newbie question on thrift if anyone else is in a situation trying to
Newbie question here. I am trying to use the django-extjs library in my django

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.