# Fetch in applcation

**URL:** <https://www.ruby-forum.com/t/fetch-in-applcation/123583>\
**Category:** Rails\
**Created:** [December 18, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/fetch-in-applcation/123583 "2007-12-18T23:05:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 18, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/fetch-in-applcation/123583/1 "2007-12-18T23:05:35Z")

</div>

Can someone have a quick gander at this application.rb file

[http://pastie.textmate.org/130228](http://pastie.textmate.org/130228)

What Im trying to do is make available to controllers lower down a  
@recipe so I don’t have to do this in every controller that needs it

recipe = User.find(session[:user\_id]).recipe.find(param[:id])

At the top of the controllers that use this I use…

before\_filter :authorize  
before\_filter :fetch\_recipe

Say the controller being used for this is an Ingredients controller  
(Recipe has many ingredients). What happens is that although I can add  
Ingredients it seaams that the flash[:notice] always seams to get set in  
the application.rb

Any ideas?

---

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 19, 2007, 6:44am UTC](https://www.ruby-forum.com/t/fetch-in-applcation/123583/2 "2007-12-19T06:44:24Z")

</div>

Hi Chris,

I think you can just reset the flash[:notice] to null value in the  
beginning of the action.so that it will show the null value or just  
check for small condition.

if flash[:notice]

# display the message.

end

Chris L. wrote:

> Can someone have a quick gander at this application.rb file
> 
> [http://pastie.textmate.org/130228](http://pastie.textmate.org/130228)
> 
> What Im trying to do is make available to controllers lower down a  
> @recipe so I don’t have to do this in every controller that needs it
> 
> recipe = User.find(session[:user\_id]).recipe.find(param[:id])
> 
> At the top of the controllers that use this I use…
> 
> before\_filter :authorize  
> before\_filter :fetch\_recipe
> 
> Say the controller being used for this is an Ingredients controller  
> (Recipe has many ingredients). What happens is that although I can add  
> Ingredients it seaams that the flash[:notice] always seams to get set in  
> the application.rb
> 
> Any ideas?

---

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 19, 2007, 9:53am UTC](https://www.ruby-forum.com/t/fetch-in-applcation/123583/3 "2007-12-19T09:53:31Z")

</div>

Mohan K. wrote:

Cheers for the reply Mohan

> I think you can just reset the flash[:notice] to null value in the  
> beginning of the action.so that it will show the null value or just  
> check for small condition.

Yeah thats one way around it, the thing is that the flash should not be  
being set at all, Ive traced this through and the code seams to happyily  
find the recipe so why on earth does it still perform the rescue action

> if flash[:notice]
> 
> # display the message.
> 
> end

I’ll check this is set in my view

Thanks for chipping in 🙂

- Chris

---

<div class="post-metadata">

**Author:** ![chrislo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5e9695/32.png) [@chrislo](https://www.ruby-forum.com/u/chrislo)\
**Post date:** [December 19, 2007, 10:10am UTC](https://www.ruby-forum.com/t/fetch-in-applcation/123583/4 "2007-12-19T10:10:55Z")

</div>

> > if flash[:notice]
> > 
> > # display the message.
> > 
> > end

Hi we do use flash[:notice] in our application but how we use is

Example:

format.js {  
render :update do |page|  
if @record.save  
flash[:success] = ‘Record created successfully!’  
@records = Record.find(:all)  
page.replace\_html ‘admin\_table\_rows’, :partial=\>‘rows’  
else  
page.replace\_html ‘new\_record’, :partial =\> ‘new’  
end

```
    end

    flash[:success] = nil
  }
```
