Paul Jonathan Thompson
2006-Jun-13 02:55 UTC
[Rails] Pass infomation between different views and controllers
Hi, I am a rails and ruby nuby :-) How do you pass data between different controllers and views? I have a page ( a quote) that I am editing url ....quote/edit/6 6 id the current id. I then go to a catalog (url....catalog) to add an item to my quote (I do this via a line_item file that the quote reads) I now want to go back to the quote. I have tried this <%= link_to ''Back to Quote'', :controller => "quote", :action => "edit", :id => @quote %> but this message Couldn''t find Client without an ID I thought that @quote would give the ID but obviously it is not doing so. Could somebody please help me sort this out? Regards, Paul
Glenn Cadman
2006-Jun-13 03:15 UTC
[Rails] Re: Pass infomation between different views and controllers
Paul Jonathan Thompson wrote:> Hi, I am a rails and ruby nuby :-) > > How do you pass data between different controllers and views? I have a > page ( a quote) that I am editing url ....quote/edit/6 6 id the > current id. I then go to a catalog (url....catalog) to add an item to > my quote (I do this via a line_item file that the quote reads) I now > want to go back to the quote. I have tried this > > <%= link_to ''Back to Quote'', :controller => "quote", :action => > "edit", :id => @quote %> > > but this message > > Couldn''t find Client without an ID > > I thought that @quote would give the ID but obviously it is not doing > so. > > Could somebody please help me sort this out? > > Regards, > > PaulWhat is key (id field) for the quote in the "line_item" table? eg. lets assume it is quote_id. :id = @line_item.quote_id or Keep the id of the quote in a session parameter? and the quote controller edit references the session parameter value? -- Posted via http://www.ruby-forum.com/.
Paul Jonathan Thompson
2006-Jun-13 03:26 UTC
[Rails] Re: Pass infomation between different views and controllers
Hi Glen, thanks for the quick response. Your suggestion of storing the quote id in a session parameter makes sense to me. However I am not quite sure how to do that. Could you give an example please. Thank you, Paul On 13/06/06, Glenn Cadman <glenn.cadman@gmail.com> wrote:> Paul Jonathan Thompson wrote: > > Hi, I am a rails and ruby nuby :-) > > > > How do you pass data between different controllers and views? I have a > > page ( a quote) that I am editing url ....quote/edit/6 6 id the > > current id. I then go to a catalog (url....catalog) to add an item to > > my quote (I do this via a line_item file that the quote reads) I now > > want to go back to the quote. I have tried this > > > > <%= link_to ''Back to Quote'', :controller => "quote", :action => > > "edit", :id => @quote %> > > > > but this message > > > > Couldn''t find Client without an ID > > > > I thought that @quote would give the ID but obviously it is not doing > > so. > > > > Could somebody please help me sort this out? > > > > Regards, > > > > Paul > > > > What is key (id field) for the quote in the "line_item" table? eg. lets > assume it is quote_id. > :id = @line_item.quote_id > > or > Keep the id of the quote in a session parameter? and the quote > controller edit references the session parameter value? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Tom Mornini
2006-Jun-13 03:32 UTC
[Rails] Re: Pass infomation between different views and controllers
quote = Quote.find(params[:id]) session[:quote_id] = quote.id P.S. Don''t forget: session[:quote_id] = nil where ever it makes sense to make it go away. -- -- Tom Mornini On Jun 12, 2006, at 8:26 PM, Paul Jonathan Thompson wrote:> Hi Glen, thanks for the quick response. Your suggestion of storing the > quote id in a session parameter makes sense to me. However I am not > quite sure how to do that. Could you give an example please. > > Thank you, > > Paul > > On 13/06/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: >> Paul Jonathan Thompson wrote: >> > Hi, I am a rails and ruby nuby :-) >> > >> > How do you pass data between different controllers and views? I >> have a >> > page ( a quote) that I am editing url ....quote/edit/6 6 id the >> > current id. I then go to a catalog (url....catalog) to add an >> item to >> > my quote (I do this via a line_item file that the quote reads) I >> now >> > want to go back to the quote. I have tried this >> > >> > <%= link_to ''Back to Quote'', :controller => "quote", :action => >> > "edit", :id => @quote %> >> > >> > but this message >> > >> > Couldn''t find Client without an ID >> > >> > I thought that @quote would give the ID but obviously it is not >> doing >> > so. >> > >> > Could somebody please help me sort this out? >> > >> > Regards, >> > >> > Paul >> >> >> >> What is key (id field) for the quote in the "line_item" table? eg. >> lets >> assume it is quote_id. >> :id = @line_item.quote_id >> >> or >> Keep the id of the quote in a session parameter? and the quote >> controller edit references the session parameter value? >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Paul Jonathan Thompson
2006-Jun-13 04:04 UTC
[Rails] Re: Pass infomation between different views and controllers
Sorry still have a problem. here is the code Here is my controller code in quote_controller.rb def edit @client = Client.find(params[:id]) session[:client_id] = Client.id end Here is the link code in the view catalog.rhtml <p><%= link_to ''Back to Quote'', :controller => "quote", :action => "edit", :id => "client_id" %></p><br /> This is the dump ActiveRecord::RecordNotFound in QuoteController#edit Couldn''t find Client with ID=client_id RAILS_ROOT: /home/pjt/quote/config/.. Application Trace | Framework Trace | Full Trace /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:955:in `find_one'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:941:in `find_from_ids'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:382:in `find'' #{RAILS_ROOT}/app/controllers/quote_controller.rb:12:in `edit'' /usr/bin/mongrel_rails:18 /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:955:in `find_one'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:941:in `find_from_ids'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:382:in `find'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in `process_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in `process'' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/rails.rb:66:in `process'' /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/rails.rb:64:in `process'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:425:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:424:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:495:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:494:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:483:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:774:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:772:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:97:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/command.rb:163:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:194 /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:955:in `find_one'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:941:in `find_from_ids'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:382:in `find'' #{RAILS_ROOT}/app/controllers/quote_controller.rb:12:in `edit'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in `process_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in `process'' /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/rails.rb:66:in `process'' /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/rails.rb:64:in `process'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:425:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:424:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:495:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:494:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:483:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:774:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel.rb:772:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:97:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/command.rb:163:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:194 /usr/bin/mongrel_rails:18 Request Parameters: {"id"=>"client_id"} Show session dump --- :quote_id: -609488102 :client_id: -609130666 flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} Thanking you in advance, Paul On 13/06/06, Tom Mornini <tmornini@infomania.com> wrote:> quote = Quote.find(params[:id]) > > session[:quote_id] = quote.id > > P.S. Don''t forget: > > session[:quote_id] = nil > > where ever it makes sense to make it go away. > > -- > -- Tom Mornini > > On Jun 12, 2006, at 8:26 PM, Paul Jonathan Thompson wrote: > > > Hi Glen, thanks for the quick response. Your suggestion of storing the > > quote id in a session parameter makes sense to me. However I am not > > quite sure how to do that. Could you give an example please. > > > > Thank you, > > > > Paul > > > > On 13/06/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: > >> Paul Jonathan Thompson wrote: > >> > Hi, I am a rails and ruby nuby :-) > >> > > >> > How do you pass data between different controllers and views? I > >> have a > >> > page ( a quote) that I am editing url ....quote/edit/6 6 id the > >> > current id. I then go to a catalog (url....catalog) to add an > >> item to > >> > my quote (I do this via a line_item file that the quote reads) I > >> now > >> > want to go back to the quote. I have tried this > >> > > >> > <%= link_to ''Back to Quote'', :controller => "quote", :action => > >> > "edit", :id => @quote %> > >> > > >> > but this message > >> > > >> > Couldn''t find Client without an ID > >> > > >> > I thought that @quote would give the ID but obviously it is not > >> doing > >> > so. > >> > > >> > Could somebody please help me sort this out? > >> > > >> > Regards, > >> > > >> > Paul > >> > >> > >> > >> What is key (id field) for the quote in the "line_item" table? eg. > >> lets > >> assume it is quote_id. > >> :id = @line_item.quote_id > >> > >> or > >> Keep the id of the quote in a session parameter? and the quote > >> controller edit references the session parameter value? > >>
Tom Mornini
2006-Jun-13 07:29 UTC
[Rails] Re: Pass infomation between different views and controllers
On Jun 12, 2006, at 9:04 PM, Paul Jonathan Thompson wrote:> Sorry still have a problem. here is the code > > Here is my controller code in quote_controller.rb > > def edit > @client = Client.find(params[:id]) > session[:client_id] = Client.idThat should be @client.id> end > > Here is the link code in the view catalog.rhtml > > <p><%= link_to ''Back to Quote'', :controller => "quote", :action => > "edit", :id => "client_id" %></p><br />That should be :id => @client -- -- Tom Mornini
Paul Jonathan Thompson
2006-Jun-13 23:09 UTC
[Rails] Re: Pass infomation between different views and controllers
Thanks for the help so far but sorry, it is still not working :-( Below is what I am getting: My code: def edit @client = Client.find(params[:id]) session[:client_id] = @Client.id end The dump: RuntimeError in QuoteController#edit Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id RAILS_ROOT: /home/pjt/quote/config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/controllers/quote_controller.rb:13:in `edit'' /usr/bin/mongrel_rails:18 ........... /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:194 /usr/bin/mongrel_rails:18 Request Parameters: {"id"=>"7"} Show session dump --- :client_id: -610612090 flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} On 13/06/06, Tom Mornini <tmornini@infomania.com> wrote:> On Jun 12, 2006, at 9:04 PM, Paul Jonathan Thompson wrote: > > > Sorry still have a problem. here is the code > > > > Here is my controller code in quote_controller.rb > > > > def edit > > @client = Client.find(params[:id]) > > session[:client_id] = Client.id > > That should be @client.id > > > end > > > > Here is the link code in the view catalog.rhtml > > > > <p><%= link_to ''Back to Quote'', :controller => "quote", :action => > > "edit", :id => "client_id" %></p><br /> > > That should be :id => @client > > -- > -- Tom Mornini > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ezra Zygmuntowicz
2006-Jun-13 23:59 UTC
[Rails] Re: Pass infomation between different views and controllers
On Jun 13, 2006, at 4:09 PM, Paul Jonathan Thompson wrote:> Thanks for the help so far but sorry, it is still not working :-( > Below is what I am getting: > > My code: > > def edit > @client = Client.find(params[:id]) > session[:client_id] = @Client.id > end >def edit @client = Client.find(params[:id]) session[:client_id] = @client.id end You need to use the same @client variable. You where using @Client instead of @client.. -Ezra> The dump: > > RuntimeError in QuoteController#edit > > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > RAILS_ROOT: /home/pjt/quote/config/.. > Application Trace | Framework Trace | Full Trace > > #{RAILS_ROOT}/app/controllers/quote_controller.rb:13:in `edit'' > /usr/bin/mongrel_rails:18 > ........... > > /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:194 > /usr/bin/mongrel_rails:18 > > Request > > Parameters: {"id"=>"7"} > > Show session dump > > --- > :client_id: -610612090 > flash: !map:ActionController::Flash::FlashHash {} > > > Response > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > On 13/06/06, Tom Mornini <tmornini@infomania.com> wrote: >> On Jun 12, 2006, at 9:04 PM, Paul Jonathan Thompson wrote: >> >> > Sorry still have a problem. here is the code >> > >> > Here is my controller code in quote_controller.rb >> > >> > def edit >> > @client = Client.find(params[:id]) >> > session[:client_id] = Client.id >> >> That should be @client.id >> >> > end >> > >> > Here is the link code in the view catalog.rhtml >> > >> > <p><%= link_to ''Back to Quote'', :controller => "quote", :action => >> > "edit", :id => "client_id" %></p><br /> >> >> That should be :id => @client >> >> -- >> -- Tom Mornini >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Paul Jonathan Thompson
2006-Jun-14 00:34 UTC
[Rails] Re: Pass infomation between different views and controllers
Thanks, I fixed that (and I should have noticed it. no excuse) However the link_to still does not seem to find the ID. The code in quote controler def edit @client = Client.find(params[:id]) session[:client_id] = @client.id end The code in the layout for link_to (catalog controller) <p><%= link_to ''Back to Quote'', :controller => "quote", :action => "edit", :id => @client %></p><br /> The URL that I am getting (no client id!) http://127.0.0.1:3000/quote/edit I am exspecting to see this - http://127.0.0.1:3000/quote/edit/7 but no go :-( The dump! ActiveRecord::RecordNotFound in QuoteController#edit Couldn''t find Client without an ID RAILS_ROOT: /home/pjt/quote/config/.. Application Trace | Framework Trace | Full Trace /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:97:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/lib/mongrel/command.rb:163:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:194 /usr/bin/mongrel_rails:18 Request Parameters: None Show session dump --- :client_id: 7 flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} On 14/06/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:> > On Jun 13, 2006, at 4:09 PM, Paul Jonathan Thompson wrote: > > > Thanks for the help so far but sorry, it is still not working :-( > > Below is what I am getting: > > > > My code: > > > > def edit > > @client = Client.find(params[:id]) > > session[:client_id] = @Client.id > > end > > > def edit > @client = Client.find(params[:id]) > session[:client_id] = @client.id > end > > > You need to use the same @client variable. You where using @Client > instead of @client.. > > -Ezra > > > > The dump: > > > > RuntimeError in QuoteController#edit > > > > Called id for nil, which would mistakenly be 4 -- if you really wanted > > the id of nil, use object_id > > > > RAILS_ROOT: /home/pjt/quote/config/.. > > Application Trace | Framework Trace | Full Trace > > > > #{RAILS_ROOT}/app/controllers/quote_controller.rb:13:in `edit'' > > /usr/bin/mongrel_rails:18 > > ........... > > > > /usr/lib/ruby/gems/1.8/gems/mongrel-0.3.12.4/bin/mongrel_rails:194 > > /usr/bin/mongrel_rails:18 > > > > Request > > > > Parameters: {"id"=>"7"} > > > > Show session dump > > > > --- > > :client_id: -610612090 > > flash: !map:ActionController::Flash::FlashHash {} > > > > > > Response > > Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} > > > > On 13/06/06, Tom Mornini <tmornini@infomania.com> wrote: > >> On Jun 12, 2006, at 9:04 PM, Paul Jonathan Thompson wrote: > >> > >> > Sorry still have a problem. here is the code > >> > > >> > Here is my controller code in quote_controller.rb > >> > > >> > def edit > >> > @client = Client.find(params[:id]) > >> > session[:client_id] = Client.id > >> > >> That should be @client.id > >> > >> > end > >> > > >> > Here is the link code in the view catalog.rhtml > >> > > >> > <p><%= link_to ''Back to Quote'', :controller => "quote", :action => > >> > "edit", :id => "client_id" %></p><br /> > >> > >> That should be :id => @client > >> > >> -- > >> -- Tom Mornini > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Seamus Gilchrist
2006-Jun-19 18:47 UTC
[Rails] Re: Re: Pass infomation between different views and controll
Ezra Zygmuntowicz wrote:> On Jun 13, 2006, at 4:09 PM, Paul Jonathan Thompson wrote: > >> Thanks for the help so far but sorry, it is still not working :-( >> Below is what I am getting: >> >> My code: >> >> def edit >> @client = Client.find(params[:id]) >> session[:client_id] = @Client.id >> end >> > def edit > @client = Client.find(params[:id]) > session[:client_id] = @client.id > end > > > You need to use the same @client variable. You where using @Client > instead of @client.. > > -EzraHi, I am also new at Rails and have been struggling with this topic. I apologize if this is not the correct way of doing things (posting a new question on a post from someone else). I want to access a variable that was set up in a controller from a different view. The code is as follows: def login if request.get? session[:user_id] = nil @user = User.new else @user = User.new(params[:user]) logged_in_user = @user.try_to_login if logged_in_user session[:user_id] = logged_in_user.id redirect_to(:action => "index") else flash[:notice] = "Invalid user/password combination" end end end in the index view, I would like to access info about this specific user. I am not sure how to recover it from the session id - or whether that is an efficient way of doing it versus keeping the whole user record in the session. index.rhtml <h1> Your Stats</h1> <%= if @user.correctCount == nil tempUserCorrect = 0 else tempUserCorrect = @user.correctCount end %> <p> Correct = <%= @tempUserCorrect %></p> <p> Incorrect = </p> it does not find @user (it has a nil value). Not sure why the @user variable from the login controller is not available in index which it redirects to. thanks for any thoughts -- Posted via http://www.ruby-forum.com/.
Tom Mornini
2006-Jun-19 19:23 UTC
[Rails] Re: Re: Pass infomation between different views and controll
On Jun 19, 2006, at 11:47 AM, Seamus Gilchrist wrote:> I am also new at Rails and have been struggling with this topic. I > apologize if this is not the correct way of doing things (posting a > new > question on a post from someone else). I want to access a variable > that > was set up in a controller from a different view. The code is as > follows:> in the index view, I would like to access info about this specific > user. > I am not sure how to recover it from the session id - or whether that > is an efficient way of doing it versus keeping the whole user > record in > the session.@logged_in_user = User.find(session[:user_id]) Don''t worry about efficiency. And, don''t store the entire object. Storing the user object will "work", but then you''ll need to keep the session user object in sync with the row in the table. -- -- Tom Mornini
Seamus Gilchrist
2006-Jun-19 19:59 UTC
[Rails] Re: Re: Re: Pass infomation between different views and cont
Tom Mornini wrote:> On Jun 19, 2006, at 11:47 AM, Seamus Gilchrist wrote: > >> I am also new at Rails and have been struggling with this topic. I >> apologize if this is not the correct way of doing things (posting a >> new >> question on a post from someone else). I want to access a variable >> that >> was set up in a controller from a different view. The code is as >> follows: > >> in the index view, I would like to access info about this specific >> user. >> I am not sure how to recover it from the session id - or whether that >> is an efficient way of doing it versus keeping the whole user >> record in >> the session. > > @logged_in_user = User.find(session[:user_id]) > > Don''t worry about efficiency. And, don''t store the entire object. > > Storing the user object will "work", but then you''ll need to keep > the session user object in sync with the row in the table. > > -- > -- Tom MorniniThanks - that works. Why do you suggest not to worry about efficiency? - curious? Seamus -- Posted via http://www.ruby-forum.com/.
Tom Mornini
2006-Jun-19 20:20 UTC
[Rails] Re: Re: Re: Pass infomation between different views and cont
On Jun 19, 2006, at 12:59 PM, Seamus Gilchrist wrote:> Tom Mornini wrote: >> On Jun 19, 2006, at 11:47 AM, Seamus Gilchrist wrote: >> >> @logged_in_user = User.find(session[:user_id]) >> >> Don''t worry about efficiency. And, don''t store the entire object. >> >> Storing the user object will "work", but then you''ll need to keep >> the session user object in sync with the row in the table. >> >> -- >> -- Tom Mornini > > > Thanks - that works. > > Why do you suggest not to worry about efficiency? - curious? > > SeamusYou''re just learning Rails. You''re at the training wheels stage, but you''re worrying about the Tour de France. Learn the framework. Learn to write apps efficiently and quickly. Apps that are easy to understand and follow, easy for yourself and others to maintain. From the guy who wrote the books: "Premature optimization is the root of all evil (or at least most of it) in programming." Source: "Donald Knuth: Computer Programming as an Art" 1974 Turing Award lecture -- -- Tom Mornini
Julian ''Julik'' Tarkhanov
2006-Jun-20 18:20 UTC
[Rails] Re: Pass infomation between different views and controllers
On 13-jun-2006, at 5:26, Paul Jonathan Thompson wrote:> Hi Glen, thanks for the quick response. Your suggestion of storing the > quote id in a session parameter makes sense to me. However I am not > quite sure how to do that. Could you give an example please. > > Thank you, > > Paul > > On 13/06/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: >> Paul Jonathan Thompson wrote: >> > Hi, I am a rails and ruby nuby :-)This is a bad approach because the "Back to whatever" links in ALL windows will lead to the latest search that was done out of any window. -- Julian ''Julik'' Tarkhanov please send all personal mail to me at julik.nl