my form is passing back turing_confirmation, I have the turing in a session variable. is this the correct way to get the turing into the params hash? params[:accounts][''turing''] = session[''turing''] Model =========================================== validates_confirmation_of :turing Controller ======================================== def create debugger cookies.delete :auth_token params[:accounts][:turing] = session[''turing''] # protects against session fixation attacks, wreaks havoc with # request forgery protection. # uncomment at your own risk # reset_session @accounts = Accounts.new(params[:accounts]) @accounts.save! self.current_accounts = @accounts redirect_back_or_default(''/'') flash[:notice] = "Thanks for signing up!" rescue ActiveRecord::RecordInvalid render :action => ''new'' end --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/27/07, spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > my form is passing back turing_confirmation, I have the turing in a > session variable. is this the correct way to get the turing into the > params hash? > > params[:accounts][''turing''] = session[''turing'']I usually use params.merge. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
could you show the newbie what that would look like? :> On Dec 27, 12:59 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/27/07, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > my form is passing back turing_confirmation, I have the turing in a > > session variable. is this the correct way to get the turing into the > > params hash? > > > params[:accounts][''turing''] = session[''turing''] > > I usually use params.merge. > > -- > Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 12/27/07, spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > could you show the newbie what that would look like? :>It''s almost what you already had: params[:account].merge( :turing => session[:turing] ) Helps one get around that false sense of encapsulation in Ruby/Rails. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hmmm still now workie.. and i can see that session[''turing''] is correct! and matches turing_confirmation in the debugger On Dec 27, 1:17 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/27/07, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > could you show the newbie what that would look like? :> > > It''s almost what you already had: > > params[:account].merge( :turing => session[:turing] ) > > Helps one get around that false sense of encapsulation in Ruby/Rails. > > -- > Greg Donaldhttp://destiney.com/--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Still not working. and it seems like the params hash cannot be modified. am i doing it wrong? class AccountsController < ApplicationController # render new.rhtml def new end def create debugger cookies.delete :auth_token # params[:accounts][''turing''] = session[''turing''] params[:accounts].merge ''turing'' => session[''turing''] puts params[:accounts] # protects against session fixation attacks, wreaks havoc with # request forgery protection. # uncomment at your own risk # reset_session @accounts = Accounts.new(params[:accounts]) @accounts.save! self.current_accounts = @accounts redirect_back_or_default(''/'') flash[:notice] = "Thanks for signing up!" rescue ActiveRecord::RecordInvalid render :action => ''new'' end def updateturing render( :partial => "createturing" ) end end On Dec 27, 1:49 pm, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmmm still now workie.. and i can see that session[''turing''] is > correct! and matches turing_confirmation in the debugger > > On Dec 27, 1:17 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 12/27/07, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > could you show the newbie what that would look like? :> > > > It''s almost what you already had: > > > params[:account].merge( :turing => session[:turing] ) > > > Helps one get around that false sense of encapsulation in Ruby/Rails. > > > -- > > Greg Donaldhttp://destiney.com/- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 12/27/07, spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Still not working. and it seems like the params hash cannot be > modified.I modify it all the time with no problems. *shrug*> am i doing it wrong? > params[:accounts].merge ''turing'' => session[''turing'']Looks fine to me. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 28, 2007, at 4:30 PM, Greg Donald wrote:> > On 12/27/07, spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> Still not working. and it seems like the params hash cannot be >> modified. > > I modify it all the time with no problems. *shrug* > >> am i doing it wrong? >> params[:accounts].merge ''turing'' => session[''turing''] > > Looks fine to me. >Based on my problem of trying to merge params into another hash, and the very interesting question raised by Mark Wilden, maybe the problem is related how you are keying your hash. I was trying to merge params into a hash keyed with symbols, and it didn''t work. But when I changed the keys to strings, it did work. So instead of params[:accounts].merge ''turing'' => session[''turing''] try params[''accounts''.merge!({''turing'' => session[''turing''}) Also notice the bang on merge! If that doesn''t work, try different possibilities with strings versus symbols. Phillip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is a standard Ruby-ism :string and ''string'' are not the same thing. The leading colon makes it into a Symbol, which is converted into a unique integer behind the scenes. This makes it useful for hashes, because you can use this value directly for the hash instead of having to process it into some kind of key the way you would if it were a String. I think the convention is that the top-level things in params (e.g. the model name) use Symbols and the lower-level stuff (as in the form arguments) are indexed with strings. It doesn''t matter which you use, as long as you are consistent, for example you could use Symbols in your session hash. String has to_sym and Symbol has to_s so you can get from one to the other easily. I feel your pain too guys, becuase I went through this one myself a couple of months ago, but I was parsing XML. This is why XmlSimple has the KeyToSymbol argument, as I discovered after running in circles for a while. HTH On Dec 28 2007, 10:49 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 28, 2007, at 4:30 PM, Greg Donald wrote: > > > > > On 12/27/07, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> Still not working. and it seems like the params hash cannot be > >> modified. > > > I modify it all the time with no problems. *shrug* > > >> am i doing it wrong? > >> params[:accounts].merge ''turing'' => session[''turing''] > > > Looks fine to me. > > Based on my problem of trying to merge params into another hash, and > the very interesting question raised by Mark Wilden, maybe the > problem is related how you are keying your hash. I was trying to > merge params into a hash keyed with symbols, and it didn''t work. But > when I changed the keys to strings, it did work. So instead of > > params[:accounts].merge ''turing'' => session[''turing''] > > try > > params[''accounts''.merge!({''turing'' => session[''turing''}) > > Also notice the bang on merge! If that doesn''t work, try different > possibilities with strings versus symbols. > > Phillip--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Merge method will return a new array unless you specify like, params = params[:accounts].merge( :turing => session[:turing] ) if it is not working still, you will have try with a different variable name. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 2, 2008, at 3:37 AM, ghoti wrote:> > I think the convention is that the top-level things in params (e.g. > the model name) use Symbols and the lower-level stuff (as in the form > arguments) are indexed with strings. It doesn''t matter which you use, > as long as you are consistent, for example you could use Symbols in > your session hash.I''m not sure your statement about it not mattering which you use is entirely accurate. I was reading an article about this (can''t remember where), and strings can have a significantly bigger impact on memory usage because each one is a completely separate identifier and therefore has its own memory space. The rule of thumb that I read (and have decided to adopt) is: if you care about the content of the thing, use a string; if it''s just an identifier, use a symbol. I''m going through my entire application changing all strings to symbols where I can, and it''s turning out to be most places. As for convention, so far all of the Rails code I''ve looked at makes almost exclusive use of symbols. In fact, now that I think about it, I can''t recall seeing the use of a string. But I haven''t scoured every line of Rails either. The easier use of symbols is why they created HashWithIndifferentAccess, which is what params is. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I''m not sure your statement about it not mattering which you use is > entirely accurate. I was reading an article about this (can''t > remember where), and strings can have a significantly bigger impact > on memory usage because each one is a completely separate identifier > and therefore has its own memory space. The rule of thumb that I1 == 1 # true "some string" == "some string" # false :some_symbol == :some_symbol # true this help anyone figure out what a symbol is? ;) (tip - think about ''=='' in terms of where the data is located in the memory) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Jan 2008, at 14:09, Shai Rosenfeld wrote:> >> I''m not sure your statement about it not mattering which you use is >> entirely accurate. I was reading an article about this (can''t >> remember where), and strings can have a significantly bigger impact >> on memory usage because each one is a completely separate identifier >> and therefore has its own memory space. The rule of thumb that I > > 1 == 1 # true > "some string" == "some string" # false > :some_symbol == :some_symbol # true >Except that irb(main):001:0> "some string" == "some string" => true The equal? method is probably what you were thinking of (since == on string is a string comparison not an object id comparison or anything like that) Fred> this help anyone figure out what a symbol is? ;) > (tip - think about ''=='' in terms of where the data is located in the > memory) > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---