0

I am very new to Rails, so bear with me while I learn.

I have a model, show, with an attribute preview_url. How can I build a call that only returns shows that have a non-null preview_url and what would be the best way to word the controller method?

i.e. localhost:3000/shows/?preview_url ??

Thanks in advance.

1
  • You should read a book on rails. That'll give you structured knowledge and save you (and us) some time :) Commented May 24, 2012 at 22:16

1 Answer 1

2

In your ShowsController you would have an action named with_preview like this:

def with_preview
  @shows = Show.where('preview_url IS NOT NULL').all
end

The url for this action would be /shows/with_preview

Sign up to request clarification or add additional context in comments.

2 Comments

I am getting Couldn't find Show with id=with_preview when I try this. I have the standard index and show methods in place.
Good practice would be creating a named scope on your model. So you would do Show.whith_preview.all. So if you do need that condition in another controller action you don't need to repeat the where clause.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.