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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:08:24+00:00 2026-05-28T15:08:24+00:00

In our Rails 3.1.0 app, we need to modify params passed to rfq controller

  • 0

In our Rails 3.1.0 app, we need to modify params passed to rfq controller in create and update. For example, we want to record the current user id under input_by_id. What we did was:

  @rfq.input_by_id = session[:user_id]

It worked as expected. Also when need_report field is false, then report_language field should be nil. We decide to add the following line in rfq controller to make sure the nil is passed to report_language when need_report is false:

  @rfq.report_language = nil unless params[:need_report]

However this addition causes the rspec case failure (in create/update of the controller) because of the data validation failure. However when we fire up the app, it behaves fine without saving the report_language when need_report is false. I am wondering if the line above is not the right way to use params[:need_report] for @rfq updating.

Thanks so much.

UPDATE:

Controller code:

  def create
    if has_create_right?
      @rfq = Rfq.new(params[:rfq], :as => :roles_new )
      @rfq.input_by_id = session[:user_id]
      #save sales_id selected
      if sales? && member? && !team_lead?
        @rfq.sales_id = session[:user_id]        
      end
      #view page may carry the hidden report language even if need_report == false
      @rfq.report_language = nil unless params[:need_report]
      #save into join table rfqs_standards
      params[:rfq][:standard_ids].each do |sid|  
        @rfq.standards << Standard.find(sid.to_i) if !sid.nil? && sid.to_i > 0 
      end unless params[:rfq][:standard_ids].nil?
      #save into join table rfqs_test_items
      params[:rfq][:test_item_ids].each do |tid|
        @rfq.test_items << TestItem.find(tid.to_i) if !tid.nil? && tid.to_i > 0 
      end unless params[:rfq][:test_item_ids].nil?
      if @rfq.save!
        redirect_to URI.escape("/view_handler?index=0&msg=RFQ saved!")
      else
        flash.now[:error] = "RFQ not saved!"
        render 'new'
      end
    else
       redirect_to URI.escape("/view_handler?index=0&msg=No rights!") 
    end
  end

Test case failed after addition of @rfq.report_language = nil unless params[:need_report]

   it "should be successful for corp head" do
      session[:corp_head] = true
      session[:user_id] = 1
      s = Factory(:standard)
      rfq = Factory.attributes_for(:rfq, :need_report => true, :report_language => 'EN')
      rfq[:standard_ids] = [s.id] # attach standard_id's to mimic the POST'ed form data
      get 'create', :rfq => rfq
      #response.should redirect_to URI.escape("/view_handler?index=0&msg=RFQ saved!")
      response.should render_template('new')
    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-28T15:08:25+00:00Added an answer on May 28, 2026 at 3:08 pm

    the problem ist that you are simply not looking at the right value.

    get 'create', :rfq => rfq will result in a params-hash like {:rfq => {...}}

    so you need to @rfq.report_language = nil unless params[:rfq][:need_report] == 'true'

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

Sidebar

Related Questions

Our app uses Rails.cache in the controller to cache some items outside the scope
There are rfqs and quotes controllers in our rails 3.1.0 app. Rfq has many
Our rails app is designed as a single code base linking to multiple client
We are getting close to releasing our new rails app and so far interest
I need to set up a payment solution within one of our Rails apps
I've been working on getting our Rails 2.3.8 app running correctly under JRuby. Everything
In our rspec test for rails 3.1.0 app, we use both Factory.build and Factory.attributes_for.
As I said in a previous post, our Rails app has to interface with
I need to access data in an MS SQL database from a rails app.
Our Rails app is using Restful Authentication for user/session management and it seems that

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.