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 !

Maxxx
  • 1,179
  • 3
  • 16
  • 21

4 Answers4

6

Try this in your find method.

render 'result', :id => @item.id, :format => :js
Dia Kharrat
  • 5,948
  • 3
  • 32
  • 43
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>
1

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

mikdiet
  • 9,859
  • 8
  • 59
  • 68
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.

kvirani
  • 76
  • 3
  • 3
  • 8