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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:55:17+00:00 2026-05-28T04:55:17+00:00

Is line number 3 in my create action considered bad practice? Because a user

  • 0

Is line number 3 in my create action considered bad practice?
Because a user has many photo_albums and an album needs to be linked to the right user I basically grab the id from current_user and store it in the user_id column of my photo_albums database table.

I’m sure this should be done from the model e.g before_save or before_create
I’m having trouble getting it to work. I created a method with an argument and tried to pass the current_user id into that method via the controller to the method written in my model then supplied that method name after before save but I either get wrong number of arguments error or undefined method.

Can some one explain how I can do this thanks very much.

  def create
    @photoalbum = PhotoAlbum.new(params[:photo_album])
    @photoalbum.user_id = current_user.id
    if @photoalbum.save
      flash[:notice] = "Successfully created gallery."
      redirect_to @photoalbum
    else
      render :action => 'new'
    end
  end

Kind regards

  • 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-28T04:55:18+00:00Added an answer on May 28, 2026 at 4:55 am

    There’s nothing wrong with this,
    but I’d be inclined to make it more specific.

    You say a user has_many :photo_album

    So instead we can say

      def create
        @photoalbum = current_user.photo_albums.build(params[:photo_album])
        if @photoalbum.save
          flash[:notice] = "Successfully created gallery."
          redirect_to @photoalbum
        else
          render :action => 'new'
        end
      end
    

    This achieves the same thing,
    but using the has_many makes it clearer our intent.

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

Sidebar

Related Questions

I'm planning to create a number-line control similar to the image below (only one
How do I find the number in line number may not be in the
I can go to a specific line number by double clicking in the status
I am trying to set the current line number to a variable in Elisp
How do I get the line number of a memo when I right click
I'm looking for a method that computes the line number of a given text
Is it possible to get the current source line number in Perl? The equivalent
In IIS 6 ASP errors were displayed with the line number and a description
Is there any way to get the source line number in Javascript, like __LINE__
I want a batch file which: removes a certain line [line number by %lnum%]

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.