ruby on rails - Create new instance of Campaign in every iteration -


i working on functionality whereby table displayed records, each radio buttons reject , approve. user selects appropriate radio button , presses process. control passed process_campaigns. here breaks down data , analyses each record's status. if approved redirects approve block , same reject.

the following parameters passed:

parameters: {"utf8"=>"✓", "authenticity_token"=>"9tcexvcmdahawgqlopdarksowbbaxzgwznra8sbnkwm=", "campaign"=>{"2"=>{"start_date"=>"2016-07-18 15:43:00", "end_date"=>"2016-10-15 12:20:00", "merchant_revenue"=>"10", "status"=>"approved", "notes"=>""}, "1"=>{"start_date"=>"2016-07-15 12:20:00", "end_date"=>"", "merchant_revenue"=>"10", "status"=>"approved", "notes"=>""}}, "commit"=>"process"}  def process_campaign   authorize! :operator, current_user.operator    params[:campaign].each |key, value|     if value[:status] == "approved"       redirect_to approve_operator_campaign_path(key), :id => key, :start_date => value[:start_date], :revenue_mode => value[:revenue_model], :end_date =>  value[:end_date], :active => true, :status => 307 , return      elsif value[:status] == "rejected"       redirect_to reject_operator_campaign_path(key), campaign_name: key, notes: value[:notes], :status => 307 , return      end   end   redirect_to operator_campaigns_path, flash: { notice: "campaigns have been processed."} end  def reject   authorize! :operator, current_user.operator   params[:campaign].each |key, value|     if value[:status] = "rejected"       @campaign = campaign.active.where(id: key, operator_id: current_user.operator_id).last!       @campaign.data.merge!({:notes=>value[:notes]})       @campaign.status = "rejected"       @campaign.save(validate: false)     end   end end  def approve   @campaign = campaign.find(params[:id])   params[:campaign].each |key, value|     if value[:status] = "approved"       @applied_campaign = appliedcampaign.new(:campaign_id => key, :start_date => value[:start_date]||time.now, :end_date =>  value[:end_date], :active => true)     end   end end 

the problem when control passed approve or reject entire campaign string passed both records contained within whereas want seperate each record , pass individually. can indicate why entire campaign string being passed?

move params inside route helper

redirect_to approve_operator_campaign_path(key, param_1: 1, param_2: 2) # parameters: { "id"=>"2" "param_1"=>"1", "param_2"=>"2" } 

change method to:

def process_campaign   authorize! :operator, current_user.operator    params[:campaign].each |key, value|     if value[:status] == "approved"       redirect_to approve_operator_campaign_path(key, id: key, start_date: value[:start_date], revenue_mode: value[:revenue_model], end_date:  value[:end_date], active: true, status: 307) , return      elsif value[:status] == "rejected"       redirect_to reject_operator_campaign_path(key, campaign_name: key, notes: value[:notes], status: 307) , return      end   end   redirect_to operator_campaigns_path, flash: { notice: "campaigns have been processed."} end 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -