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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:14:22+00:00 2026-05-14T20:14:22+00:00

so I have this big method in my application for newsletter distribution. Method is

  • 0

so I have this big method in my application for newsletter distribution. Method is for updating rayons and I need to assign a user to rayon. I have relation n:n through table colporteur_in_rayons which has attributes since_date and until_date.

I am a junior programmer and I know this code is pretty dummy 🙂
I appreciate every suggestion.

def update
  rayon = Rayon.find(params[:id])
  if rayon.update_attributes(params[:rayon])
    if params[:user_id] != ""
      unless rayon.users.empty?
        unless rayon.users.last.id.eql?(params[:user_id])
          rayon.colporteur_in_rayons.last.update_attributes(:until_date => Time.now)
          Rayon.assign_user(rayon.id,params[:user_id])
          flash[:success] = "Rayon #{rayon.name} has been succesuly assigned to #{rayon.actual_user.name}."
          return redirect_to rayons_path
        end
      else
         Rayon.assign_user(rayon.id,params[:user_id])
         flash[:success] = "Rayon #{rayon.name} has been successfully assigned to #{rayon.actual_user.name}."
         return redirect_to rayons_path
      end
    end
    flash[:success] = "Rayon has been successfully updated."
    return redirect_to rayons_path
  else
    flash[:error] = "Rayon has not been updated."
    return redirect_to :back
  end
end
  • 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-14T20:14:23+00:00Added an answer on May 14, 2026 at 8:14 pm
    def update
        rayon = Rayon.find(params[:id])
    
        unless rayon.update_attributes(params[:rayon])
            flash[:error] = "Rayon not updated."
            return redirect_to :back
        end
    
        puid = params[:user_id]
        empty = rayon.users.empty?
    
        if puid == "" or (not empty and rayon.users.last.id.eql?(puid))
            msg = "Rayon updated.",
        else
            msg = "Rayon #{rayon.name} assigned to #{rayon.actual_user.name}.",
            rayon.colporteur_in_rayons.last.update_attributes(
                :until_date => Time.now) unless empty
            Rayon.assign_user(rayon.id, puid)
        end
    
        flash[:success] = msg[msg_i]
        return redirect_to rayons_path
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ application which makes extensively use of pointers to maintain quite
I have a rather large application which, on the admin frontend, takes a few
In my application I work with criterias. I have one base Criteria interface and
I'm writing a simple application in vb.net and need to output some information to
This is the situation: I'm working on a project where I need to be
I have DotNetOpenAuth running on a background thread making calls to Google authorized with
I have to display around 100 icons (each 50x50) in Button. I am downloading
What are the advantages/disadvantages to each method? I know I've read somewhere in either
I wrote some code to connect the application to it's database, then I created
I have an app that is using devise for authentication. Rails 3 on ruby

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.