Smplifying my nested if statement

I have trouble in building nested if statements. Kindly please help and
correct me. I have an index page in which I show records based on some
condition. My controller code for that is,

def index_orderSummary
if Date.today.month>=4
@order_summary =
OrderSummary.where(:created_at=>("#{Time.now.year}-04-01")…("#{Time.now.year+1}-03-31"))
else
@order_summary =
OrderSummary.where(:created_at=>("#{Time.now.year-1}-04-01")…("#{Time.now.year}-03-31"))
end
@order_summary = @order_summary.paginate(page:
params[:page]).per_page(10).order(“order_no ASC”)
end

I have used a search box for which I have written the following method
in the controller.

def search
if params[:id] == “search-order” then
@order_summary =
OrderSummary.where(:created_at=>("#{Time.now.year}-04-01")…("#{Time.now.year+1}-03-31")).search(params[:search])
@order_summary = @order_summary.paginate(page:
params[:page]).per_page(5).order(‘order_no ASC’)
render :action => :index_orderSummary
elsif params[:id] == “search-issue” then
@issue =
Issue.where(:created_at=>("#{Time.now.year}-04-01")…("#{Time.now.year+1}-03-31")).search(params[:search])
@issue = @issue.paginate(page:
params[:page]).per_page(10).order(“issue_slip_no ASC”)
render :action => :index_issues
elsif params[:id] == “search-labour”
@labour =
Labour.where(:created_at=>("#{Time.now.year}-04-01")…("#{Time.now.year+1}-03-31")).search(params[:search])
@labour = @labour.paginate(page:
params[:page]).per_page(10).order(“issue_slip_no ASC”)
render :action => :index_labour
end
end

now what all I need is, I want to integrate both my search and index

methods.

My index methods already having an if else statement., now i want to
check if params comes from search then I want to display the searched
results in the index. How do I achieve that? Pls intimate, if my
question is not clear…

Thanks in advance.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs