>>text_field("post", "title", "size" => 20)will generate:>><input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" />so, when you name "post", there is a way to translate this word to "@post", an object''s name. how can I do that? -- 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 -~----------~----~----~----~------~----~------~--~---
and i saw: def link_to_page(page_name, web = @web, text = nil, options = {}) .... end in a helper file. what does "web = @web" do here? -- 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 -~----------~----~----~----~------~----~------~--~---
Nanyang Zhan wrote:> >>text_field("post", "title", "size" => 20) > will generate: > >><input type="text" id="post_title" name="post[title]" size="20" value="#{@post.title}" /> > > so, when you name "post", there is a way to translate this word to > "@post", an object''s name. how can I do that?In your view you can do this with: object_name = "post" instance_variable_get("@#{object_name}") However, most of the time you should use @post directly. Dan Manges --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nanyang Zhan wrote:> and i saw: > def link_to_page(page_name, web = @web, text = nil, options = {}) > .... > end > > in a helper file. > what does "web = @web" do here?It means if "web" is not passed in to the link_to_page method, it defaults to the value of @web. link_to_page(:page_name) #=> uses @web link_to_page(:page_name, :my_web) #=> uses :my_web Dan Manges --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dan Manges wrote:>> what does "web = @web" do here? > > It means if "web" is not passed in to the link_to_page method, it > defaults to the value of @web. >Thanks Dan. What about my first question? I defined a helper method, namely address_field(object_name) I used it in a view file like address_field("school") now I want to use @school.city inside this method, how can I do that? I don''t want to put @school.city inside directly, because this helper method will be used by other objects. -- 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 -~----------~----~----~----~------~----~------~--~---
Dan Manges wrote:> In your view you can do this with: > object_name = "post" > instance_variable_get("@#{object_name}")> Dan MangesI am sorry, I replied before I saw your first post. I added @object = instance_variable_get("@#{object_name}") in to the method, I can use @object.city now. Thanks again! -- 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 -~----------~----~----~----~------~----~------~--~---