Hi, I''ve got a basic question but I just can''t find a way or example to do it. I have a DIV in my rhtml: <div id="error_div" style="position: absolute; left: 500px; top: 500px; visibility: hidden"> Some text about errors </div> What I''d like to do is to make it visible from the controller. I''ve tried things like page[:error_div].show but that complains about undefined page... What would be the way to do that simple thing? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
Use ''render :update'' in your controller action: render :update do |page| # manipulate page here end On 25 Nov., 11:50, Jo Gr <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, I''ve got a basic question but I just can''t find a way or example to > do it. > > I have a DIV in my rhtml: > > <div id="error_div" style="position: absolute; left: 500px; top: 500px; > visibility: hidden"> > Some text about errors > </div> > > What I''d like to do is to make it visible from the controller. > > I''ve tried things like page[:error_div].show but that complains about > undefined page... > > What would be the way to do that simple thing? > > Thanks! > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Stefan Lang wrote:> Use ''render :update'' in your controller action: > > render :update do |page| > # manipulate page here > endHi, thanks Stefan. I actually tried that and now I''m sure that was the right direction. The problem is that when that is executed I get a windows dialog asking me to download a file. The file contents are: try { $("error_div").show();} catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''$(\"error_div\").show();''); throw e } I run the browser in RadRails - Aptana IDE and I guess that uses Explorer. Might be a setting in the browser (?) Regards -- 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 -~----------~----~----~----~------~----~------~--~---
Without seeing your code I am just guessing here, but make sure your link_to_remote (or other remote call) does not contain the :update => some_id option. If it does, the rjs won''t be executed by the browser. -Bill comopasta Gr wrote:> Stefan Lang wrote: > >> Use ''render :update'' in your controller action: >> >> render :update do |page| >> # manipulate page here >> end >> > > Hi, thanks Stefan. I actually tried that and now I''m sure that was the > right direction. > > The problem is that when that is executed I get a windows dialog asking > me to download a file. The file contents are: > > try { $("error_div").show();} catch (e) { alert(''RJS error:\n\n'' + > e.toString()); alert(''$(\"error_div\").show();''); throw e } > > I run the browser in RadRails - Aptana IDE and I guess that uses > Explorer. Might be a setting in the browser (?) > > Regards >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, here''s what I have. 1- A simple view where there''s a form. When I click create button it will execute the function in the controller. That page also contains the div "error_div" that I want to make visible if there are some errors. <%= start_form_tag({ :action => ''create'' }, :multipart => true) %> <%= render :partial => ''form'' %> <div id="submit_button" style="position: absolute; left: 10px; top: 428px;"> <%= submit_tag "Create" %> </div> <%= end_form_tag %> <div id="error_div" style="position: absolute; left: 500px; top: 500px; visibility: hidden"> Error message </div> 2- The controller will execute the create function. What I do there is checking some of the fields in the form. If there is a problem with those I just want to show up the error_div. def create if check_parameters_for_new_tab() == -1 puts "returned error -1" render :update do |page| page[:error_div].show() end # render :action => ''new'' return end (I had some problems with validates_presence_of that''s Why I decided to check the form myself...) 3- The partial is shown next in case you wonder what it contains... <div id="mandatory_fields" style="position: absolute; left: 10px; top: 100px;"> <h3>Mandatory fields</h3> <p><label for="tab_name">Name</label><br/> <%= text_field ''tab'', ''name'' %></p> <p><label for="tab_palo">Palo</label><br/> <%= text_field ''tab'', ''palo'' %></p> <p><label for="tab_picture">Tab Picture</label><br/> <%= file_field_tag "tab_picture" %></p> <p><label for="tab_audio">Tab Audio</label><br/> <%= file_field_tag "tab_audio" %></p> </div> Thanks for checking. -- 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 -~----------~----~----~----~------~----~------~--~---
That won''t work because the form is being submitted through a standard post rather than an xhr call. Take a look at the api docs for form_remote_tag at http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000535. -Bill comopasta Gr wrote:> Hi, > > here''s what I have. > > 1- A simple view where there''s a form. When I click create button it > will execute the function in the controller. That page also contains the > div "error_div" that I want to make visible if there are some errors. > > <%= start_form_tag({ :action => ''create'' }, :multipart => true) %> > <%= render :partial => ''form'' %> > > <div id="submit_button" style="position: absolute; left: 10px; top: > 428px;"> > <%= submit_tag "Create" %> > </div> > > <%= end_form_tag %> > > <div id="error_div" style="position: absolute; left: 500px; top: 500px; > visibility: hidden"> > Error message > </div> > > > > > 2- The controller will execute the create function. What I do there is > checking some of the fields in the form. If there is a problem with > those I just want to show up the error_div. > > def create > if check_parameters_for_new_tab() == -1 > puts "returned error -1" > render :update do |page| > page[:error_div].show() > end > # render :action => ''new'' > return > end > > > (I had some problems with validates_presence_of that''s Why I decided to > check the form myself...) > > > 3- The partial is shown next in case you wonder what it contains... > > <div id="mandatory_fields" style="position: absolute; left: 10px; top: > 100px;"> > <h3>Mandatory fields</h3> > > <p><label for="tab_name">Name</label><br/> > <%= text_field ''tab'', ''name'' %></p> > > <p><label for="tab_palo">Palo</label><br/> > <%= text_field ''tab'', ''palo'' %></p> > > <p><label for="tab_picture">Tab Picture</label><br/> > <%= file_field_tag "tab_picture" %></p> > > <p><label for="tab_audio">Tab Audio</label><br/> > <%= file_field_tag "tab_audio" %></p> > > </div> > > > Thanks for checking. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
William Pratt wrote:> That won''t work because the form is being submitted through a standard > post rather than an xhr call. Take a look at the api docs for > form_remote_tag at > http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000535. > > -BillThanks again Bill. I tried to use form_remote_tag and for a moment I though it would do it. However I found out that it is not possible to upload files (multipart is not working). And one of the fields contains a binary file. So, I''m back at the beginning. There''s some option to use hidden frames to make uploads with AJAX, but I don''t want to rewrite everything. validates_presence_of is able to toggle a div and change its contents. Any ideas where I can see how that is done there? Cheers! -- 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 -~----------~----~----~----~------~----~------~--~---
In your controller, if your object is not valid, just render the action again. In the view, add an if around the div or set a variable equal to ''hidden'' or ''visible'' and use it directly in your style tag. That would only display the div if there are errors. Slightly dirty, but it will work. -Bill comopasta Gr wrote:> William Pratt wrote: > >> That won''t work because the form is being submitted through a standard >> post rather than an xhr call. Take a look at the api docs for >> form_remote_tag at >> http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000535. >> >> -Bill >> > > > Thanks again Bill. I tried to use form_remote_tag and for a moment I > though it would do it. However I found out that it is not possible to > upload files (multipart is not working). And one of the fields contains > a binary file. So, I''m back at the beginning. There''s some option to use > hidden frames to make uploads with AJAX, but I don''t want to rewrite > everything. > > validates_presence_of is able to toggle a div and change its contents. > Any ideas where I can see how that is done there? > > Cheers! > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Check out the blog post at CodeFU: http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent I''ve tried a few plugins to do ajax-like file upload but this simple, clean approach has been the best so far. On Nov 25, 4:27 pm, comopasta Gr <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> William Pratt wrote: > > That won''t work because the form is being submitted through a standard > > post rather than an xhr call. Take a look at the api docs for > > form_remote_tag at > >http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.... > > > -Bill > > Thanks again Bill. I tried to use form_remote_tag and for a moment I > though it would do it. However I found out that it is not possible to > upload files (multipart is not working). And one of the fields contains > a binary file. So, I''m back at the beginning. There''s some option to use > hidden frames to make uploads with AJAX, but I don''t want to rewrite > everything. > > validates_presence_of is able to toggle a div and change its contents. > Any ideas where I can see how that is done there? > > Cheers! > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
William Pratt wrote:> set a variable equal to ''hidden'' or ''visible''Excellent! That''s making the trick perfectly. Thanks! I''ll check those plugins once I move to a more "AJAXized" version I am planning. Cheers! -- 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 -~----------~----~----~----~------~----~------~--~---