I have the following code in my index.rhtml: <div id="how_many_images" style="background-color:#eee;"> <%= render(:partial => ''form'') %></div> ...and the following in my _form.rhtml <%= form_remote_tag(:update => "images_div_main", :url => { :action => ''get_reordered_images''}) %> <label for="num_images_requested">How many images?</label> <%= text_field_tag :numreq %> <%= submit_tag "Click to get images" %> <%= end_form_tag %> ...and of course, this im my Mycontroller_controller.rb: def get_reordered_images @sock_serv = TCPSocket.new("192.168.107.7", 9000) xml = "<?xml version=''1.0'' ?>" @sock_serv.send(xml,0) @results = @sock_serv.recv(1000) @sock_serv.close render(:layout => false) end and I even have this in my get_reordered_images.rhtml file: <%= @results %> It works great! Gets me what I want, where I want it on the page. But what I also want to do, is "execute" this "action" when the page is first rendered. I feel like I should just "call" this from the index page, perhaps is ruby brackets, but I''ve spent ours and nothing happens until I do the form_remote_tag click and then the "replacement" partial page appears. What do I need to do to have "get_reorder_images" execute on first rendering of html. Eventually, I will put in logic or a new "action" so that some parameters are passed with subsequent calls, but this first call has a default mode. Thanks, Dave -- Posted via http://www.ruby-forum.com/.
Okay, I figured this one out. I have to: <%= render(:partial => ''get_reordered_images'') %> in my index.rhtml file Then create a _get_reordered_images file in my application''s Views file in which I only have: <%= render_component(:action => ''get_reordered_images'') %> Which calls my "def get_reordered_images" action in my controller.rb file. Now I have two really nagging questions: 1. Can someone explain to me why this is "efficient" (to have all of these different types of files just passing along a slightly altered call...I know there must be an abstract explanation, but my trivial application does show it)? 2. How come some posts that can be really complicated receive multiple comments almost immediately, but most of my posts asking simple questions, most of the time get no responses? I''m guessing the multi-post responses are a tight group of colleagues and my questions are not of interest, but maybe I''m asking them the wrong way. Thoughts? Comments? write to me directly at DTL "at" Stanfordalumni.org (I''m afraid I won''t scroll down to find if anyone posted to me). David T-L wrote:> I have the following code in my index.rhtml: > <div id="how_many_images" style="background-color:#eee;"> > <%= render(:partial => ''form'') %></div> > > ...and the following in my _form.rhtml > <%= form_remote_tag(:update => "images_div_main", > :url => { :action => > ''get_reordered_images''}) %> > <label for="num_images_requested">How many images?</label> > <%= text_field_tag :numreq %> > <%= submit_tag "Click to get images" %> > <%= end_form_tag %> > > ...and of course, this im my Mycontroller_controller.rb: > def get_reordered_images > @sock_serv = TCPSocket.new("192.168.107.7", 9000) > xml = "<?xml version=''1.0'' ?>" > @sock_serv.send(xml,0) > @results = @sock_serv.recv(1000) > @sock_serv.close > render(:layout => false) > end > > and I even have this in my get_reordered_images.rhtml file: > <%= @results %> > > It works great! Gets me what I want, where I want it on the page. But > what I also want to do, is "execute" this "action" when the page is > first rendered. I feel like I should just "call" this from the index > page, perhaps is ruby brackets, but I''ve spent ours and nothing happens > until I do the form_remote_tag click and then the "replacement" partial > page appears. > > What do I need to do to have "get_reorder_images" execute on first > rendering of html. > > Eventually, I will put in logic or a new "action" so that some > parameters are passed with subsequent calls, but this first call has a > default mode. > > Thanks, > Dave-- Posted via http://www.ruby-forum.com/.
I literally lol''d when I had the ephiphany (re my # 2 question below) that when someone responds to your post, the post goes back to the top. I didn''t know that!! So those posts that show 12 responses in 2 minutes really mean that the last response was two minutes ago, not all 12 of them. Doh! David T-L wrote:> Okay, I figured this one out. I have to: > <%= render(:partial => ''get_reordered_images'') %> in my index.rhtml file > > Then create a _get_reordered_images file in my application''s Views file > in which I only have: > <%= render_component(:action => ''get_reordered_images'') %> > > Which calls my "def get_reordered_images" action in my controller.rb > file. > > Now I have two really nagging questions: > 1. Can someone explain to me why this is "efficient" (to have all of > these different types of files just passing along a slightly altered > call...I know there must be an abstract explanation, but my trivial > application does show it)? > > 2. How come some posts that can be really complicated receive multiple > comments almost immediately, but most of my posts asking simple > questions, most of the time get no responses? > > I''m guessing the multi-post responses are a tight group of colleagues > and my questions are not of interest, but maybe I''m asking them the > wrong way. > > Thoughts? Comments? write to me directly at DTL "at" Stanfordalumni.org > (I''m afraid I won''t scroll down to find if anyone posted to me). > David T-L wrote:-- Posted via http://www.ruby-forum.com/.
On Feb 18, 2006, at 10:51 AM, David T-L wrote:> 2. How come some posts that can be really complicated receive > multiple > comments almost immediately, but most of my posts asking simple > questions, most of the time get no responses?I have no direct knowledge of your past posts, but I know that from my perspective when a poster asks a trivial question that can be answered via Google and/or a reading of the Rails book, I don''t bother to respond. When a person asks a question that is unique (and perhaps difficult), then I want to respond and join because it''s breaking new ground. -- -- Tom Mornini
Tom, I appreciate your feedback. For me, I don''t ask questions until I''ve been spinning for a few hours. I can tell you that with the structure of Ruby on Rails and Ajax, there are assumptions of location going on under the covers that, as a newbie, it is hard to know when something isn''t possible versus when I''m misunderstanding the difference between a method, a module, a helper, and a component. I sit here with both "Agile Web Development with Rails" and the pickaxe "Programming Ruby" and I''m all over Google with searches, especially for error messages. For example, I thought I should initialize a flag ($new_search) in the controller. The flag is used by a action (method? component?) in the controller. Now, it appears the flag gets "re-initialized" everytime the action is called. Okay. But I don''t want to put this code in my index.rhtml file to initialize it (by that I mean give it the value true when the page first renders). So where should I initialize the flag? I''m sure this is a trivial question, but for a newbie it opens up a whole vista of "getting it". Thanks, Dave Tom Mornini wrote:> On Feb 18, 2006, at 10:51 AM, David T-L wrote: > >> 2. How come some posts that can be really complicated receive >> multiple >> comments almost immediately, but most of my posts asking simple >> questions, most of the time get no responses? > > I have no direct knowledge of your past posts, but I know that from my > perspective when a poster asks a trivial question that can be answered > via Google and/or a reading of the Rails book, I don''t bother to > respond. > > When a person asks a question that is unique (and perhaps difficult), > then > I want to respond and join because it''s breaking new ground. > > -- > -- Tom Mornini-- Posted via http://www.ruby-forum.com/.
On Feb 18, 2006, at 12:45 PM, David T-L wrote:> For example, I thought I should initialize a flag ($new_search) in the > controller. The flag is used by a action (method? component?) in the > controller. Now, it appears the flag gets "re-initialized" everytime > the action is called. Okay. But I don''t want to put this code in my > index.rhtml file to initialize it (by that I mean give it the value > true > when the page first renders).Here''s the rub, and I''m only saying this to be helpful, and I''m certainly only speaking for myself. Have you seen any other code, in the Pickaxe or AWDR or Google seaches on Rails subjects, that have variables that begin with a dollar sign? Ruby variables are not prefixed by dollar signs. This mailing list is comprised of some of the most helpful and knowledgeable people as any I''ve ever subscribed to. That said, a mailing list is NOT intended as a programming peer that you can just shoot questions out to, as though all the members are sitting next to you in a small room. So, aforementioned helpful and knowledgeable people on the list will give more time and attention to people that have clearly spent *enough* time to get familiar with the environment. Since they did this themselves, they know where the sticking point are, as nearly each and everyone of them started in the same place you did: new to Ruby, new to Rails, coming from another language, Pickaxe and AWDR on knee. Now, to answer your question: You *cannot*, under any circumstances with Rails, store values that will persist from one request to the next by using in memory variables. Doesn''t matter where they''re set, doesn''t matter what kind they are. The only way to persist values across requests is via session (disregarding roll your own inter request mechanisms). As a general style suggestion, I don''t think anyone would give you advice to set any sort of flag in a view. Setting a flag is about controlling the application, and therefore belongs in the controller. -- -- Tom Mornini
Tom Mornini wrote: Thanks for directing your comments in a constructive way. I appreciate that it would be easier to "walk away".> > Here''s the rub, and I''m only saying this to be helpful, and I''m > certainly only speaking for myself. > > Have you seen any other code, in the Pickaxe or AWDR or Google > seaches on > Rails subjects, that have variables that begin with a dollar sign? Ruby > variables are not prefixed by dollar signs.I know this isn''t really your main point, but it did make me wonder how I got off on my global variable track. I could NOT find ANY code using $nnnnn (I was surprised, I would have sworn I saw it!), but I did find some examples (Pickaxe pp 15, 17) where $ is used to demonstrate an example of a Global variable. I finally remembered why I started using it: Pickaxe p.331. I was having problems figuring out what was controlling what and I needed to use a variable in an action and figure out why it was getting changed or not set. In my simplistic approach, I figured I''d avoid the "problems" of "undefined variable or method".> Now, to answer your question: You *cannot*, under any circumstances with > Rails, store values that will persist from one request to the next by > using in memory variables. Doesn''t matter where they''re set, doesn''t > matter what kind they are. The only way to persist values across > requests > is via session (disregarding roll your own inter request mechanisms).That would have been good to read (or remember if I had read it). I''m coming from a ''non-session'', non-object enviornment, so I wasn''t thinking of my process in that way. Clear to me now!> As a general style suggestion, I don''t think anyone would give you > advice > to set any sort of flag in a view. Setting a flag is about controlling > the application, and therefore belongs in the controller.I buy into that, that''s what was puzzling me. Thanks for helping me understand the best use of this forum. Dave -- Posted via http://www.ruby-forum.com/.