On Saturday, 21 April 2012 04:44:57 UTC-4, Colin Law wrote: > > On 21 April 2012 09:35, amvis <[email protected]> wrote: > > > > > > On Saturday, 21 April 2012 04:19:05 UTC-4, Colin Law wrote: > >> > >> On 21 April 2012 09:14, amvis <[email protected]> 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 [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. > > -- 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 [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.

