Guest User

Untitled

a guest
Jun 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <div class="admin__link-add-btn">
  2. <%= link_to 'Ajouter un lien', new_link_path, class: "add-link btn btn-outline-success btn-sm article__add-btn" %>
  3. </div>
  4.  
  5. <div class="admin__link-select">
  6. <%= grouped_collection_select :link, :link_id, Category.order(:name).includes(:links), :links, :name, :id, :name %>
  7. </div>
  8. <div class="form_container">
  9. <%= render 'links/form' %>
  10. </div>
  11.  
  12.  
  13. <div class="admin__link-manag-btn">
  14. <%= link_to "Supprimer", link_path(Link.last), class: "btn-delete-custom btn btn-outline-danger btn-sm ", data: {:confirm => "Etes vous sur?"}, method: :delete %>
  15. <%= link_to "Editer", link_path(Link.last), class: "btn-delete-custom btn btn-outline-primary btn-sm "%>
  16. </div>
  17.  
  18. class LinksController < ApplicationController
  19.  
  20. def index
  21. @links = Link.all
  22.  
  23. end
  24.  
  25. def create
  26. @link = Link.new(link_params)
  27. if @link.save
  28. flash[:notice] = "Sucess"
  29. else
  30. flash.now[:alert] = "Error"
  31. end
  32. redirect_to root_path
  33. end
  34. def new
  35. @link = Link.new
  36. end
  37. def update
  38. @link.update(link_params)
  39. redirect_to root_path
  40. end
  41.  
  42. def destroy
  43. @link = Link.find(params[:id])
  44.  
  45. if @link.destroy
  46. flash[:notice] = "Success"
  47. redirect_to root_path
  48. else
  49. flash[:alert] = "Error"
  50. redirect_to root_path
  51. end
  52. end
  53.  
  54. def admin
  55. @links = Link.all
  56. end
  57.  
  58. private
  59.  
  60. def link_params
  61. params.require(:link).permit(:name, :url, :category_id)
  62. end
  63.  
  64. def find_link
  65. @link = Link.find(params[:id])
  66. end
  67. end
  68.  
  69. <%= simple_form_for(@link = Link.new, remote: true) do |f| %>
  70. <% if @link.errors.any? %>
  71. <div id="error_explanation">
  72. <h2>
  73. <%= "Errors:" %>
  74. </h2>
  75. <ul>
  76. <% @link.errors.full_messages.each do |msg| %>
  77. <li>
  78. <%= msg %>
  79. </li>
  80. <% end %>
  81. </ul>
  82. </div>
  83. <% end %>
  84.  
  85.  
  86. <div class="form-group">
  87. <%= f.input :name, label: "Name", class: "form-control" %>
  88. </div>
  89. <div class="form-group">
  90. <%= f.input :url, label: "Url", class: "form-control" %>
  91. </div>
  92. <div class="form-group">
  93. <%= f.input :category_id, prompt: "- Category -", label: false, collection: Category.order('name') %>
  94. </div>
  95.  
  96.  
  97.  
  98. <div class="form-group" data-id='<%=@link.id %>'>
  99. <%= f.button :submit, @link.new_record? ? "Create" : "Update", class: 'links_add-userlink-button btn btn-outline-primary btn-sm'%>
  100. </div>
  101.  
  102. <% end %>
Add Comment
Please, Sign In to add comment