Is it possible to have more than one kind of view for a specific action, for example an .rhtml and a .rjs file to handle the view for the same action? I suspect not, but this makes me wonder if there a way to call the .rjs file from within the .rhtml so the statements within it get executed? Thanks, Andy
> Is it possible to have more than one kind of view for a specific action, > for example an .rhtml and a .rjs file to handle the view for the same > action? > > I suspect not, but this makes me wonder if there a way to call the .rjs > file from within the .rhtml so the statements within it get executed? >http://api.rubyonrails.org/classes/ActionController/MimeResponds/InstanceMethods.html#M000062 Regards, Rimantas -- http://rimantas.com/
Thank you Rimantas, I am sorry but should have clarified that I wanted to be able to use the two views together for the single action, the page you pointed me to answers the question the way I posted it but I should have elaborated, apologies! Basically, I want my .rhtml view file to be the display portion for the given action but I also want it to be able to trigger the javascrpt calls from a corresponding .rjs file, and this I am not quite sure how to accomplish. A quick of summary of what I want to accomplish is having do_stuff.rhtml display the given page for an action ( do_stuff ) but also have do_stuff.rjs contain javascript commands to show and hide different elements on the page, I am not sure how to get to the .rjs file from the .rhtml file. Thanks! Andy Rimantas Liubertas wrote:>> Is it possible to have more than one kind of view for a specific action, >> for example an .rhtml and a .rjs file to handle the view for the same >> action? >> >> I suspect not, but this makes me wonder if there a way to call the .rjs >> file from within the .rhtml so the statements within it get executed? >> > > http://api.rubyonrails.org/classes/ActionController/MimeResponds/InstanceMethods.html#M000062 > > Regards, > Rimantas > -- > http://rimantas.com/-- Posted via http://www.ruby-forum.com/.
Rimantas Liubertas
2006-Apr-07 15:03 UTC
[Rails] Re: Multiple view types for a single action?
<...>> A quick of summary of what I want to accomplish is having do_stuff.rhtml > display the given page for an action ( do_stuff ) but also have > do_stuff.rjs contain javascript commands to show and hide different > elements on the page, I am not sure how to get to the .rjs file from the > .rhtml file.You may check render :update http://api.rubyonrails.org/classes/ActionController/Base.html#M000206 (search for "Rendering inline JavaScriptGenerator page updates") and http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html These shoul let you to achieve the effect you want. If you want to use ready made .rjs then I have no answer yet, and it would be interesting to find out if there is a way to do it. Regards, Rimantas -- http://rimantas.com/
Andrew Cowan
2006-Apr-07 15:32 UTC
[Rails] Re: Re: Multiple view types for a single action?
Thats terrific, if I could get that to work it would certainly be an acceptable solution, but I get errors -> I have the following div containers in my .rhtml page: <div id="stuff1_div" style="display:none"> </div> <div id="stuff2_div" style="display:none"> </div> and added this inline javascript using the api as an example: <% render :update do |page| page[''stuff1_div''].show page[''stuff2_div''].show end %> which is giving me these errors: try { $(''stuff1_div'').show(); $(''stuff2_div'').show(); } catch (e) { alert(''RJS error ..., etc Any idea what I did wrong, I know page[''div_id_here''].hide/show works from inside an .rjs template so am confused why it is not working here. Thanks again! Andy Rimantas Liubertas wrote:> <...> >> A quick of summary of what I want to accomplish is having do_stuff.rhtml >> display the given page for an action ( do_stuff ) but also have >> do_stuff.rjs contain javascript commands to show and hide different >> elements on the page, I am not sure how to get to the .rjs file from the >> .rhtml file. > > You may check render :update > http://api.rubyonrails.org/classes/ActionController/Base.html#M000206 > (search for > "Rendering inline JavaScriptGenerator page updates") > and > http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html > > These shoul let you to achieve the effect you want. If you want to use > ready made .rjs > then I have no answer yet, and it would be interesting to find out if > there is a way to do it. > > > Regards, > Rimantas > -- > http://rimantas.com/-- Posted via http://www.ruby-forum.com/.
Rimantas Liubertas
2006-Apr-07 16:04 UTC
[Rails] Re: Re: Multiple view types for a single action?
<...>> and added this inline javascript using the api as an example: > > <%> render :update do |page| > page[''stuff1_div''].show > page[''stuff2_div''].show > end > %> > > which is giving me these errors: > > try { $(''stuff1_div'').show(); $(''stuff2_div'').show(); } catch (e) { > alert(''RJS error ..., etc > > Any idea what I did wrong, I know page[''div_id_here''].hide/show works > from inside an .rjs template so am confused why it is not working here.You can use render :update in _controller''s action_ which responds to AJAX request. If you want to have this update code in your normal _view_ use update_page_tag, like this: <%= update_page_tag do |page| page[''stuff1_div''].show page[''stuff2_div''].show end %> Regards, Rimantas -- http://rimantas.com/
Andrew Cowan
2006-Apr-07 16:49 UTC
[Rails] Re: Re: Re: Multiple view types for a single action?
Thats awesome, exactly what I needed to know, thank you very much for taking the time to illustrate this stuff! :) -Andy Rimantas Liubertas wrote:> <...> >> >> try { $(''stuff1_div'').show(); $(''stuff2_div'').show(); } catch (e) { >> alert(''RJS error ..., etc >> >> Any idea what I did wrong, I know page[''div_id_here''].hide/show works >> from inside an .rjs template so am confused why it is not working here. > > You can use render :update in _controller''s action_ which responds to > AJAX request. > > If you want to have this update code in your normal _view_ use > update_page_tag, like this: > > <%= update_page_tag do |page| > page[''stuff1_div''].show > page[''stuff2_div''].show > end > %> > > > Regards, > Rimantas > -- > http://rimantas.com/-- Posted via http://www.ruby-forum.com/.