# Flickr - Tutorial

**URL:** <https://www.ruby-forum.com/t/flickr-tutorial/54518>\
**Category:** Rails\
**Created:** [March 7, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518 "2006-03-07T17:02:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 7, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/1 "2006-03-07T17:02:34Z")

</div>

So I’ve pretty much followed the steps in the video tutorial on [RoR.com](http://RoR.com)  
for creating a small app, to search for photos on [flickr.com](http://flickr.com) - all is  
good, and works as intended to…

How would I go about adding validation, so if no tags are specified it  
will fail. I know I have to use validates\_presence\_of :tags - but not  
in the controller… so I tried to generate a model called ‘search’  
(the form name) and added the validates\_presence\_of :tags - but it is  
still not working.

What am I doing wrong ?

Regards,

/mich

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 7, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/2 "2006-03-07T17:09:58Z")

</div>

On 3/7/06, mich [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How would I go about adding validation, so if no tags are specified it  
> will fail. I know I have to use validates\_presence\_of :tags - but not in the  
> controller…

The “validates\_\*” methods are part of ActiveRecord, so they won’t work  
in  
the Flickr demo at all.

You could write your own method in the controller.

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 7, 2006, 5:19pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/3 "2006-03-07T17:19:06Z")

</div>

mich wrote:

> 

In this case, you are not trying to save your information to a  
database. This is a query, not a model. That means using the  
validates… methods in ActiveRecord models is the wrong solution.

What you can do is to verify the information in the controller like  
this:

@tags = params[:tags]  
if @tags.is\_empty?  
flash[:notice] = “You must supply a tag”  
redirect\_to ‘search’  
end

In short, you pull the tags out of the params array and perform your  
checks there.

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 7, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/4 "2006-03-07T18:32:18Z")

</div>

Berin L. wrote:

> @tags = params[:tags]  
> if @tags.is\_empty?  
> flash[:notice] = “You must supply a tag”  
> redirect\_to ‘search’  
> end

Actually this is not working. is\_empty is not a method - and by changing  
it to @tags.empty? I still cannot get it to work.

/mich

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 7, 2006, 6:44pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/5 "2006-03-07T18:44:23Z")

</div>

On 3/7/06, mich [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Actually this is not working. is\_empty is not a method - and by changing  
> it to @tags.empty? I still cannot get it to work.

The problem with the Flickr tutorial, is that it’s using an Ajax  
response,  
which waxes weirdly with redirect, in my experience.

Try this:

def search  
flickr = Flickr.new ‘YOUR-API-KEY’  
if (@params[:tags].empty?)  
render (:text =\> “You must supply a tag to search for”)  
else  
render :partial =\> ‘photo’, :collection =\>  
flickr.photos(:tags=\> params[:tags], :per\_page =\> ‘24’)  
end  
end

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 7, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/6 "2006-03-07T18:10:28Z")

</div>

Berin L. wrote:

> In this case, you are not trying to save your information to a  
> database. This is a query, not a model. That means using the  
> validates… methods in ActiveRecord models is the wrong solution.
> 
> What you can do is to verify the information in the controller like  
> this:
> 
> @tags = params[:tags]  
> if @tags.is\_empty?  
> flash[:notice] = “You must supply a tag”  
> redirect\_to ‘search’  
> end
> 
> In short, you pull the tags out of the params array and perform your  
> checks there.

Make sense !  
Thanks !

/mich

---

<div class="post-metadata">

**Author:** ![mich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@mich](https://www.ruby-forum.com/u/mich)\
**Post date:** [March 8, 2006, 10:27am UTC](https://www.ruby-forum.com/t/flickr-tutorial/54518/7 "2006-03-08T10:27:30Z")

</div>

Joshua W. wrote:

> Try this:
> 
> def search  
> flickr = Flickr.new ‘YOUR-API-KEY’  
> if (@params[:tags].empty?)  
> render (:text =\> “You must supply a tag to search for”)  
> else  
> render :partial =\> ‘photo’, :collection =\>  
> flickr.photos(:tags=\> params[:tags], :per\_page =\> ‘24’)  
> end  
> end

Works like a charm !

Thanks.

/mich
