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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:05:33+00:00 2026-06-03T00:05:33+00:00

I had a general question of what is going on when code like this

  • 0

I had a general question of what is going on when code like this runs:

<%= form_for(current_user.favorite_relationships.find_by_lesson_id(@lesson),
             html: {method: :delete},
             remote: true) do |f| %>
             <div><%= f.hidden_field :lesson_id %></div>
  <%= f.submit "Unfavorite", class: "btn btn-large" %>
<% end %>

specifically the very first line of code. i usually see some form of instance variable instead of

current_user.favorite_relationships.find_by_lesson_id

I can assume that this will go into the FavoriteRelationship controller’s destroy action. Is there anything else someone can infer from that form above? Like what will be available or gets passed in the destroy action?

  • 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-03T00:05:35+00:00Added an answer on June 3, 2026 at 12:05 am

    Presumably, the controller has supplied a Lesson object to the view through the variable @lesson. Your current user, a User object, presumably has_many :favorite_relationships, which in turn belongs_to :lesson, meaning there is a field within the favorite_relationships table called lesson_id.

    Rails builds “magic” finder methods for your models for the fields it contains. If a model has a lesson_id field, Rails provides a find_by_lesson_id helper. Rails is smart enough to extract @lesson.id when you pass it an actual Lesson object instead of an integer.

    The net result is that an object of type FavoriteRelationship is being passed into the form_for helper. This is no different than finding the object in the controller and passing it to the view via a (for example) @favorite_relationship variable.

    what will be available or gets passed in the destroy action?

    The only thing available to the controller on the subsequent request to the FavoriteRelationship’s destroy route is the id of the object to destroy. You’ll be able to access it via params[:id].

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

Sidebar

Related Questions

I had a general question about extracting code from a visual studio web test.
This question aims to understand RoR and frameworks in general. It looks like RoR
just had a general question about how to approach a certain problem I'm facing.
This is a very general question but it's based on a specific problem. I've
This started out as a general user question on Android forums. However it's become,
I've been learning to develop in Android and had more of a general question:
I don't have IE9 to mess around with this, so it's a general question.
This is a more direct question stemming from an earlier more general question i
So this is a pretty general question, but I've been wondering about it for
I'm working in AS3, but I guess this could be a general question, so

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.