Hi,
I have a method called by GET myapp/products

when products is called it returns data to render

in a particular point inside of that render I would like to call a
method that I generally call by
GET myapp/news
allow that method to render and put it into my combined output.
in other words something that might be better suited to an Ajax
request or an Iframe but currently I would like it to execute in one
single request.

To retrieve the rendered data from my second method would I have to
do it as a HTTP GET? or is there some other Rails way.

If there is some other Rails way how should I structure it so I can
pass in a parameter to the method that is normally passed via the
querystring?

Thanks,
Bryan Rasmussen

--
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@googlegroups.com.
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.

Search Discussions

  • Colin Law at Jan 3, 2012 at 4:55 pm

    On 3 January 2012 15:44, bryan wrote:
    Hi,
    I have a method called by GET myapp/products

    when products is called it returns data to render

    in a particular point inside of that render I would like to call a
    method that I generally call by
    GET myapp/news
    allow that method to render and put it into my combined output.
    in other words something that might be better suited to an Ajax
    request or an Iframe but currently I would like it to execute in one
    single request.

    To retrieve the rendered data from my second method  would I have to
    do it as a HTTP GET? or is there some other Rails way.
    Read up on view helpers and partials for ideas on how to do this.
    Extract the common code out to a helper and call it from both actions.

    Colin

    --
    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@googlegroups.com.
    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.
  • Peter Vandenabeele at Jan 3, 2012 at 5:09 pm

    On Tue, Jan 3, 2012 at 4:44 PM, bryan wrote:

    Hi,
    I have a method called by GET myapp/products

    when products is called it returns data to render

    in a particular point inside of that render I would like to call a
    method that I generally call by
    GET myapp/news
    allow that method to render and put it into my combined output.
    in other words something that might be better suited to an Ajax
    request or an Iframe but currently I would like it to execute in one
    single request.

    To retrieve the rendered data from my second method would I have to
    do it as a HTTP GET? or is there some other Rails way.

    If there is some other Rails way how should I structure it so I can
    pass in a parameter to the method that is normally passed via the
    querystring?
    If I understand correctly, there are 2 views that share some common part
    (that you want to show in a product view and a news view).

    You could place the common part in a partial e.g.

    app/views/news/_latest_news.html.haml <= note the underscore at the
    start of the file name

    and include that partial from the view for products and news.

    If there are data required, pass them to the partial via locals.

    Like this in http://guides.rubyonrails.org/layouts_and_rendering.html

    3.4.4 Passing Local Variables

    You can also pass local variables into partials, making them even more
    powerful and flexible. For example, you can use this technique to reduce
    duplication between new and edit pages, while still keeping a bit of
    distinct content:

    - new.html.erb

    <h1>New zone</h1>
    <%= error_messages_for :zone %>
    <%= render :partial => "form", :locals => { :zone => @zone } %>

    For you that could be something like (untested !)

    product.html.haml

    = render "news/latest_news" # note NO underscore here and NO .html.haml

    HTH,

    Peter

    --
    Peter Vandenabeele
    http://twitter.com/peter_v
    http://rails.vandenabeele.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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 3, '12 at 4:22p
activeJan 3, '12 at 5:09p
posts3
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase