Rails : how to render an other action in the controller, in js not in html?
Asked Answered
G

4

5

I have two actions in my controller :

def find
  @item = Item.find(params[:id])
  render 'result', :id => @item.id
end

def result
  @item = Item.find(params[:id])
  respond_to do |format|
    format.js
  end
end

The issue in that I call first the find action, then it calls the result action but in the html format. So the 'format.js` is never triggered.

How can render, at the end of the find action, the result action in the js format ?

Thanks a lot !

Gobelin answered 31/3, 2012 at 20:14 Comment(1)
It would help if you would tag this with the programming language.Watercool
I
6

Try this in your find method.

render 'result', :id => @item.id, :format => :js
Italianism answered 31/3, 2012 at 20:28 Comment(0)
C
1

render method only renders views, doesn't call another action

Chelonian answered 31/3, 2012 at 20:28 Comment(0)
A
1

The bigger issue here is that you are trying to call another action, which breaks MVC pattern. Even though actions are defined as methods, think of them as something else, that cannot call other actions.

Also, please reply with code from your views that are calling/trigger these actions.

Adaminah answered 31/3, 2012 at 23:50 Comment(0)
D
1
Try this

<%= render 'components/activity-slider', populer_packages: @populer_packages %>

    components/activity-slider

    <div class="slider sliderSecondary activitiesSlider">
    <% populer_packages.each do |package| %>
        <a href="#" class="sliderGrid ">
          <div class="sliderCont">
            <div class="sliderGradient"></div>
            <div class="sliderThumb">
              <div class="sliderImgWrap">
                <%= image_tag "#{package.image}", class: "img-fluid sliderImg" %>
                <div class="overlayCaptionCont">
                  <div class="overlayCaptionWrap">
                    <div class="overlayCaption">
                      <ul class="list-unstyled captionList">
                        <li>test</li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </a>
      <% end %>
    </div>
Denationalize answered 29/11, 2018 at 4:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.