On Sunday, 22 April 2012 07:10:02 UTC-4, Colin Law wrote:
>
> On 22 April 2012 11:59, amvis <[email protected]> wrote: 
> > 
> > 
> > On Sunday, 22 April 2012 06:51:09 UTC-4, Colin Law wrote: 
> >> 
> >> On 22 April 2012 11:49, Colin Law <[email protected]> wrote: 
> >> > On 22 April 2012 11:45, amvis <[email protected]> wrote: 
> >> >> 
> >> >>       i have used 
> >> >> 
> >> >> this 
> http://rails-bestpractices.com/posts/57-substituting-before_filter-load_object,
>  
>
> >> >> but i didn't get that correctly, when i use the access 
> >> >> specifier(private,protected),i am trying that for 2 days, i have got 
> >> >> the 
> >> >> issues...can u rearrange with the above code, for accessing 
> >> >> instance variable in all action... 
> >> > 
> >> > Show us what you tried and what happened. 
> >> 
> >> Just use a simple before_filter initially to get it working. 
> >> 
> >>  class BranchesController < ApplicationController 
> >>      before_filter :create 
> >> 
> >>     def branch 
> >>       @branch = Branch.new 
> > 
> >          puts "name...#{@name}"  //i didn't get the @name variable 
> >> 
> >>     end 
> >> 
> >>     def create 
> >>       @branch = Branch.new(params[:branch]) 
> >>       @name = "vishnu" 
> >>     end 
> >>   end 
> > 
> >   Here the create is my calling function,i mean when i click the button 
> that 
> > create function will call, ie Branches#create. 
>
> Don't try and call one of the actions in the filter.  Add a new method 
> that is called from the before filter and sets up what you want, so 
> possibly 
> before_filter :setup 
>
> and 
>
> private 
>   def* setup *
>     @name = "vishnu" 
>   end 
>     

Thanks colin, thank you
when i compare this code with my application code, in the above code, 
before doing all the method, the *setup* method will run, and set the 
variables, so that can be accessed for all methods. But here i have one 
doubt, This is my application structure.....

*-Myapp*

    * -Controller*
           ->pages_controller.rb
     *-View*
           *-pages*
              ->page.html.erb

*class PagesController < ApplicationController*

def *page*
     
end

*end*
My doubt is if i display any variable(example is @name = vishnu) in 
page.html.erb, i have to  create one *page* action in PagesController..? or 
any other way to access....?




 

> Then setup will be called before each action. 
> By putting it in the private section of the controller the setup 
> method is not available as an action itself, but just as a method that 
> can be called within the controller 
>
> Colin 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/DrTc15i64s0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to