Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Best way to split up search by


  • Please log in to reply
3 replies to this topic

#1 Jamie

Jamie

    Controller

  • Moderators
  • 114 posts
  • LocationThe UK

Posted 28 August 2013 - 12:04 PM

Hey guys

 

I'm creating an application which lists reports which users should be able to search by the fields 'reference_id', 'test_id' and 'category'.

 

Now..

 

There is to be 3 boxes on the Reports homepage which display an input for the reference ID and Test ID with a submit button along with a dropdown list for the category with a submit button.

 

In my controller simply called 'ReportsController' I have the following actions

def all
    @reports = Report.where(visible: true)
  end

  def reference
    @reports = Report.where(reference_id: params[:ref_id], visible: true)
  end

  def test
    @reports = Report.where(test_id: params[:test_id], visible: true)
  end

  def product
    @reports = []
  end

Is this the correct way or would you advise another way?

 

 

Cheers folks :)


Rails developer based in Newcastle, UK.
Web app owner - Twitter lover

#2 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 28 August 2013 - 03:01 PM

That's a tough one. I have an adage that I think applies to this: "If it works, don't fix it" and "There are no right ways and no wrong ways, only better ways and worse ways"

 

Yes I know that's two sayings!

 

Seriously, in this case I think it's pretty safe to say that what works for you is fine and I see nothing wrong with what you have as this is clearly not a CRUD situation.

 

My opinion is that you have a reports controller and therefore a reports views folder where you can keep all your reports. That makes perfect sense, but it is only an opinion. You know best what it is you want to achieve.


  • Jamie likes this

Programming is just about problem solving!


#3 Jamie

Jamie

    Controller

  • Moderators
  • 114 posts
  • LocationThe UK

Posted 28 August 2013 - 03:27 PM

That's a tough one. I have an adage that I think applies to this: "If it works, don't fix it" and "There are no right ways and no wrong ways, only better ways and worse ways"

 

Yes I know that's two sayings!

 

Seriously, in this case I think it's pretty safe to say that what works for you is fine and I see nothing wrong with what you have as this is clearly not a CRUD situation.

 

My opinion is that you have a reports controller and therefore a reports views folder where you can keep all your reports. That makes perfect sense, but it is only an opinion. You know best what it is you want to achieve.

 

Cheers mate.

 

I know what you're saying I just wanted to put it out there to the world to see if I was thinking straight or I was a million miles off.

 

It's been one of those days...


  • james likes this
Rails developer based in Newcastle, UK.
Web app owner - Twitter lover

#4 Adam

Adam

    Inspector

  • Administrators
  • 71 posts

Posted 28 August 2013 - 04:10 PM

What James says is pretty much spot on.

 

I've done the same myself when generating reports and just have a ReportsController which has a view for each type of report which should be generated.


  • james likes this

Adam Cooke

from aTech Media - UK-based Ruby on Rails developers. 

 

Follow me on Twitter  •  Check out my code on GitHub  •  Take a look at my designs





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users