Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="admin__link-add-btn">
- <%= link_to 'Ajouter un lien', new_link_path, class: "add-link btn btn-outline-success btn-sm article__add-btn" %>
- </div>
- <div class="admin__link-select">
- <%= grouped_collection_select :link, :link_id, Category.order(:name).includes(:links), :links, :name, :id, :name %>
- </div>
- <div class="form_container">
- <%= render 'links/form' %>
- </div>
- <div class="admin__link-manag-btn">
- <%= link_to "Supprimer", link_path(Link.last), class: "btn-delete-custom btn btn-outline-danger btn-sm ", data: {:confirm => "Etes vous sur?"}, method: :delete %>
- <%= link_to "Editer", link_path(Link.last), class: "btn-delete-custom btn btn-outline-primary btn-sm "%>
- </div>
- class LinksController < ApplicationController
- def index
- @links = Link.all
- end
- def create
- @link = Link.new(link_params)
- if @link.save
- flash[:notice] = "Sucess"
- else
- flash.now[:alert] = "Error"
- end
- redirect_to root_path
- end
- def new
- @link = Link.new
- end
- def update
- @link.update(link_params)
- redirect_to root_path
- end
- def destroy
- @link = Link.find(params[:id])
- if @link.destroy
- flash[:notice] = "Success"
- redirect_to root_path
- else
- flash[:alert] = "Error"
- redirect_to root_path
- end
- end
- def admin
- @links = Link.all
- end
- private
- def link_params
- params.require(:link).permit(:name, :url, :category_id)
- end
- def find_link
- @link = Link.find(params[:id])
- end
- end
- <%= simple_form_for(@link = Link.new, remote: true) do |f| %>
- <% if @link.errors.any? %>
- <div id="error_explanation">
- <h2>
- <%= "Errors:" %>
- </h2>
- <ul>
- <% @link.errors.full_messages.each do |msg| %>
- <li>
- <%= msg %>
- </li>
- <% end %>
- </ul>
- </div>
- <% end %>
- <div class="form-group">
- <%= f.input :name, label: "Name", class: "form-control" %>
- </div>
- <div class="form-group">
- <%= f.input :url, label: "Url", class: "form-control" %>
- </div>
- <div class="form-group">
- <%= f.input :category_id, prompt: "- Category -", label: false, collection: Category.order('name') %>
- </div>
- <div class="form-group" data-id='<%=@link.id %>'>
- <%= f.button :submit, @link.new_record? ? "Create" : "Update", class: 'links_add-userlink-button btn btn-outline-primary btn-sm'%>
- </div>
- <% end %>
Add Comment
Please, Sign In to add comment