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
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 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.