jeudi 29 décembre 2016

Dynamically generate link_to for different models using common partial - Rails 4

i want to use a common partial to render a listing page and its going good expect i am facing a problem to generate dynamic link_to for :edit and :delete action which is common.

so i have @menu and @picture model in two different views rendering the same common partial (which i created).

this is my common partial.

shared/_index_common_grid.html.erb

               <% pictures.each do |picture| %>
                  <div class="col-sm-4 pull-left">
                      <div class="thumbnail">
                          <div class="caption"> 
                               <h4><%= picture.title.capitalize%></h4>
                              <p class="text-muted">
                              <!--THIS IS WHERE I WANT TO HANDLE DYNAMIC GENERATION OF LINK_TO FOR @picture and @menu models --> 
                                 <%= link_to "Edit", [:edit, current_user,@request,@shop,picture]%>
                              |  <%= link_to "Delete", [current_user,@request,@shop,picture],:data=>{:confirm=>"Are you sure ?"}%>
                              | <span class="pull-right"><%= show_formatted_date(picture.created_at)%></span>                                
                              </p>
                          </div>
                      </div>
                  </div> 
                <%end%>

this is my one view using above common partial,there is one more similar to this except i pass different model.

##my view page --------pictures/index
                  <%unless @pictures.blank?%>   
                      <%= render partial: "shared/index_common_grid", locals: {pictures: @pictures}%>
                  <%end%>

I dont want to go with switch case in application_helper which can be done easily.

Aucun commentaire:

Enregistrer un commentaire