class BranchesController < ApplicationController def branch @branch = Branch.new (params[:branch]) branch_back = @branch.*branch* end end in the model have one *branch.rb* class Branch def branch end end In the view have one branches folder, also have the branch.html.erb in that folder. <%= form_for(@branch) do |f| %> <%end%> *routes.rb* * * match ''branch'' => ''branches#branch'' resources :branches *i am getting this following error* *NoMethodError in BranchesController#branch* *You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each* What am I doing wrong? Thank you vishnu * * * * * * -- 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/-/anCewQjZXw8J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I have changed the code like this class BranchesController < ApplicationController def branch @branch = Branch.new end def create @branch = Branch.new(params[:branch]) end end branch.html.erb in branches folder <%= form_for(@branch) do |f| %> <%end%> Now the problem is if i want to display some value from branches controller to branch.html.erb, i have to define that in branch method in BranchesController, but here all the functionality can be done in create method in BranchesController, so that way i didn''t get any values in branch.html.erb, How to do that....?. How to write that in branch method?.. if the branch method not in BranchesController, the error will be *undefined method model_name nill class*, also if the create method not in BranchesController, the error will be *the action create not found* What am i doing wrong thanks.. On Saturday, 21 April 2012 01:21:51 UTC-4, amvis wrote:> > class BranchesController < ApplicationController > def branch > @branch = Branch.new (params[:branch]) > branch_back = @branch.*branch* > end > end > > in the model have one *branch.rb* > class Branch > def branch > end > end > > In the view have one branches folder, also have the branch.html.erb in > that folder. > <%= form_for(@branch) do |f| %> > <%end%> > > *routes.rb* > * > * > match ''branch'' => ''branches#branch'' > resources :branches > > *i am getting this following error* > *NoMethodError in BranchesController#branch* > > *You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each* > > What am I doing wrong? > Thank you > > vishnu > > * > * > > * > * > > * > * > >-- 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/-/765tgLwVuLwJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-21 07:56 UTC
Re: Re: issues with changing directory structure in rails3
On 21 April 2012 08:39, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have changed the code like this > class BranchesController < ApplicationController > def branch > @branch = Branch.new > end > > def create > @branch = Branch.new(params[:branch]) > end > end > branch.html.erb in branches folder > > <%= form_for(@branch) do |f| %> > <%end%> > > > Now the problem is if i want to display some value from branches controller > to branch.html.erb, i have to define that in branch method > in BranchesController, but here all the functionality can be done in create > method in BranchesController, so that way i didn''t get any values in > branch.html.erb, How to do that....?. How to write that in branch method?.. > if the branch method not in BranchesController, the error will be undefined > method model_name nill class, also if the create method not > in BranchesController, the error will be the action create not found > > What am i doing wrongI don''t have much idea about what problem you are trying to describe, I presume English is not your first language and understand it can be difficult to explain a problem clearly. If I am right then you have an action branch in the branches controller but have the problem that in order for data to be seen in the view then you have to setup variables in that action. If you don''t want to set them up there then possibly a before_filter is what you want. If I am not understanding the problem correctly then please try again to explain it. Cut your example down to the absolute minimum code required and show what you are trying to do and what the problem is. After writing your description of the problem imagine yourself as someone who knows nothing about your requirement, read your description carefully, and make sure the description of the problem is clear. Colin> thanks.. > > > > On Saturday, 21 April 2012 01:21:51 UTC-4, amvis wrote: >> >> class BranchesController < ApplicationController >> def branch >> @branch = Branch.new (params[:branch]) >> branch_back = @branch.branch >> end >> end >> >> in the model have one branch.rb >> class Branch >> def branch >> end >> end >> >> In the view have one branches folder, also have the branch.html.erb in >> that folder. >> <%= form_for(@branch) do |f| %> >> <%end%> >> >> routes.rb >> >> match ''branch'' => ''branches#branch'' >> resources :branches >> >> i am getting this following error >> >> NoMethodError in BranchesController#branch >> >> You have a nil object when you didn''t expect it! >> You might have expected an instance of Array. >> The error occurred while evaluating nil.each >> >> What am I doing wrong? >> Thank you >> >> vishnu >> >> >> >> > -- > 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/-/765tgLwVuLwJ. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Saturday, 21 April 2012 03:56:02 UTC-4, Colin Law wrote:> > On 21 April 2012 08:39, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have changed the code like this > > class BranchesController < ApplicationController > > def branch > > @branch = Branch.new > > end > > > > def create > > @branch = Branch.new(params[:branch]) > > end > > end > > branch.html.erb in branches folder > > > > <%= form_for(@branch) do |f| %> > > <%end%> > > > > > > Now the problem is if i want to display some value from branches > controller > > to branch.html.erb, i have to define that in branch method > > in BranchesController, but here all the functionality can be done in > create > > method in BranchesController, so that way i didn''t get any values in > > branch.html.erb, How to do that....?. How to write that in branch > method?.. > > if the branch method not in BranchesController, the error will be > undefined > > method model_name nill class, also if the create method not > > in BranchesController, the error will be the action create not found > > > > What am i doing wrong > > I don''t have much idea about what problem you are trying to describe, > I presume English is not your first language and understand it can be > difficult to explain a problem clearly. If I am right then you have > an action branch in the branches controller but have the problem that > in order for data to be seen in the view then you have to setup > variables in that action. If you don''t want to set them up there then > possibly a before_filter is what you want. >Thanks colin, what i am trying to do, *branches_controller* * * class BranchesController < ApplicationController def branch @branch = Branch.new end def create @branch = Branch.new(params[:branch]) @name = "vishnu" end end *branch.html.erb* <h4> new <%=@name %> </h4> <%= form_for(@branch) do |f| %> <%= f.submit "Save" %> <%end%> if i have to get @name in branch.html.erb, i have to define that branch action in BranchesController, am i correct...?. So in this application all the main function done in create action in BranchesController. In that way how to get that values in branch.html.erb Vishnu> If I am not understanding the problem correctly then please try again > to explain it. Cut your example down to the absolute minimum code > required and show what you are trying to do and what the problem is. > After writing your description of the problem imagine yourself as > someone who knows nothing about your requirement, read your > description carefully, and make sure the description of the problem is > clear. > > Colin > > > thanks.. > > > > > > > > On Saturday, 21 April 2012 01:21:51 UTC-4, amvis wrote: > >> > >> class BranchesController < ApplicationController > >> def branch > >> @branch = Branch.new (params[:branch]) > >> branch_back = @branch.branch > >> end > >> end > >> > >> in the model have one branch.rb > >> class Branch > >> def branch > >> end > >> end > >> > >> In the view have one branches folder, also have the branch.html.erb in > >> that folder. > >> <%= form_for(@branch) do |f| %> > >> <%end%> > >> > >> routes.rb > >> > >> match ''branch'' => ''branches#branch'' > >> resources :branches > >> > >> i am getting this following error > >> > >> NoMethodError in BranchesController#branch > >> > >> You have a nil object when you didn''t expect it! > >> You might have expected an instance of Array. > >> The error occurred while evaluating nil.each > >> > >> What am I doing wrong? > >> Thank you > >> > >> vishnu > >> > >> > >> > >> > > -- > > 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/-/765tgLwVuLwJ. > > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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/-/QR-AYZO2oh4J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-21 08:19 UTC
Re: Re: issues with changing directory structure in rails3
On 21 April 2012 09:14, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ... > what i am trying to do, > > branches_controller > > class BranchesController < ApplicationController > def branch > @branch = Branch.new > end > > def create > @branch = Branch.new(params[:branch]) > @name = "vishnu" > end > end > > branch.html.erb > <h4> new <%=@name %> </h4> > <%= form_for(@branch) do |f| %> > <%= f.submit "Save" %> > <%end%> > > if i have to get @name in branch.html.erb, i have to define that branch > action in BranchesController, am i correct...?. So in this application all > the main function done in create action in BranchesController. In that way > how to get that values in branch.html.erbUse before_filter to setup @name for both create and branch. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Saturday, 21 April 2012 04:19:05 UTC-4, Colin Law wrote:> > On 21 April 2012 09:14, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > ... > > what i am trying to do, > > > > branches_controller > > > > class BranchesController < ApplicationController > > def branch > > @branch = Branch.new > > end > > > > def create > > @branch = Branch.new(params[:branch]) > > @name = "vishnu" > > end > > end > > > > branch.html.erb > > <h4> new <%=@name %> </h4> > > <%= form_for(@branch) do |f| %> > > <%= f.submit "Save" %> > > <%end%> > > > > if i have to get @name in branch.html.erb, i have to define that branch > > action in BranchesController, am i correct...?. So in this application > all > > the main function done in create action in BranchesController. In that > way > > how to get that values in branch.html.erb > > ThanksCan i do like that, class BranchesController < ApplicationController before_filter :branch,:create def branch @branch = Branch.new end def create @branch = Branch.new(params[:branch]) @name = "vishnu" end end Is it correct way...?> Use before_filter to setup @name for both create and branch. > > 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/-/TfDKhbzW_zkJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-21 08:44 UTC
Re: Re: issues with changing directory structure in rails3
On 21 April 2012 09:35, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Saturday, 21 April 2012 04:19:05 UTC-4, Colin Law wrote: >> >> On 21 April 2012 09:14, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > ... >> > what i am trying to do, >> > >> > branches_controller >> > >> > class BranchesController < ApplicationController >> > def branch >> > @branch = Branch.new >> > end >> > >> > def create >> > @branch = Branch.new(params[:branch]) >> > @name = "vishnu" >> > end >> > end >> > >> > branch.html.erb >> > <h4> new <%=@name %> </h4> >> > <%= form_for(@branch) do |f| %> >> > <%= f.submit "Save" %> >> > <%end%> >> > >> > if i have to get @name in branch.html.erb, i have to define that branch >> > action in BranchesController, am i correct...?. So in this application >> > all >> > the main function done in create action in BranchesController. In that >> > way >> > how to get that values in branch.html.erb >> > Thanks > Can i do like that, > > class BranchesController < ApplicationController > before_filter :branch,:create > > def branch > @branch = Branch.new > end > > def create > @branch = Branch.new(params[:branch]) > @name = "vishnu" > end > end > > Is it correct way...?No, have a look at the Rails Guide on Action Controller Overview to see how to use it. Also google for rails before_filter to find many examples and documentation. Colin> > >> >> Use before_filter to setup @name for both create and branch. >> >> 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/-/TfDKhbzW_zkJ. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Saturday, 21 April 2012 04:44:57 UTC-4, Colin Law wrote:> > On 21 April 2012 09:35, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Saturday, 21 April 2012 04:19:05 UTC-4, Colin Law wrote: > >> > >> On 21 April 2012 09:14, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > ... > >> > what i am trying to do, > >> > > >> > branches_controller > >> > > >> > class BranchesController < ApplicationController > >> > def branch > >> > @branch = Branch.new > >> > end > >> > > >> > def create > >> > @branch = Branch.new(params[:branch]) > >> > @name = "vishnu" > >> > end > >> > end > >> > > >> > branch.html.erb > >> > <h4> new <%=@name %> </h4> > >> > <%= form_for(@branch) do |f| %> > >> > <%= f.submit "Save" %> > >> > <%end%> > >> > > >> > if i have to get @name in branch.html.erb, i have to define that > branch > >> > action in BranchesController, am i correct...?. So in this application > >> > all > >> > the main function done in create action in BranchesController. In that > >> > way > >> > how to get that values in branch.html.erb > >> > > Thanks > > Can i do like that, > > > > class BranchesController < ApplicationController > > before_filter :branch,:create > > > > def branch > > @branch = Branch.new > > end > > > > def create > > @branch = Branch.new(params[:branch]) > > @name = "vishnu" > > end > > end > > > > Is it correct way...? > > No, have a look at the Rails Guide on Action Controller Overview to > see how to use it. Also google for > rails before_filter > to find many examples and documentation. >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... Thank you vishnu> Colin > > > > > > >> > >> Use before_filter to setup @name for both create and branch. > >> > >> 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/-/TfDKhbzW_zkJ. > > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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/-/34ctDF_QYKIJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-22 10:49 UTC
Re: Re: issues with changing directory structure in rails3
On 22 April 2012 11:45, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-22 10:51 UTC
Re: Re: issues with changing directory structure in rails3
On 22 April 2012 11:49, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 22 April 2012 11:45, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sunday, 22 April 2012 06:51:09 UTC-4, Colin Law wrote:> > On 22 April 2012 11:49, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > On 22 April 2012 11:45, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 buttonthat create function will call, ie *Branches#create.* * What am i wrong...?* * Thank you* * vishnu*> 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/-/0h7PdewiV4QJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-22 11:10 UTC
Re: Re: issues with changing directory structure in rails3
On 22 April 2012 11:59, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Sunday, 22 April 2012 06:51:09 UTC-4, Colin Law wrote: >> >> On 22 April 2012 11:49, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> > On 22 April 2012 11:45, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sunday, 22 April 2012 07:10:02 UTC-4, Colin Law wrote:> > On 22 April 2012 11:59, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Sunday, 22 April 2012 06:51:09 UTC-4, Colin Law wrote: > >> > >> On 22 April 2012 11:49, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> > On 22 April 2012 11:45, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Apr-23 07:44 UTC
Re: Re: issues with changing directory structure in rails3
On 23 April 2012 04:55, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ... > 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....?Sorry, no idea what you mean. 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.