Git Product home page Git Product logo

remote_bootstrap_modal's Introduction

Remote Bootstrap Modal

A tiny Rails engine that helps you loading remote links into a bootstrap modal.

It was created based on the following post: https://jtway.co/5-steps-to-add-remote-modals-to-your-rails-app-8c21213b4d0c

Installation

Add this line to your application's Gemfile:

bundle add remote_bootstrap_modal

Requirements

  • Rails
  • Bootstrap

Usage

  1. Make sure you have bootstrap in your application
  2. Add this gem to your Gemfile
  3. Add the following div <div id="modal-holder"></div> to your application layout (the modal will be rendered inside it)
  4. Add //= require remote_bootstrap_modal to your app/assets/javascripts/application.js (after jquery)
  5. Set the formats you need to respond with respond_to (ex: respond_to :html, :json)
  6. Call respond_modal_with in your controller passing the arguments you need
  7. Pass data: { modal: true } to links you want to load into a modal (ex: link_to 'Customers', customers_path, class: 'btn btn-default', data: { modal: true })

Example

# app/controllers/messages_controller.rb
class MessagesController < ApplicationController
  respond_to :html, :json

  def new
    @message = Message.new
    respond_modal_with @message
  end

  def create
    @message = Message.create(message_params)
    respond_modal_with @message, location: messages_path
  end

  private

  def set_message
    @message = Message.find(params[:id])
  end

  def message_params
    params.require(:message).permit(:name, :body)
  end
end
<%# app/views/messages/index.html.erb %>
<%= link_to 'Add Message', new_message_path, class: 'btn', data: { modal: true } %>

<%# app/views/messages/_form.html.erb %>
<%= simple_form_for(@message, remote: request.xhr?, html: { data: { modal: true } }) %>

Customization

It is an engine, you can override any file to customize, you can create a app/views/layouts/modal.html.erb for instance with the modal layout you want.

License

The gem is available as open source under the terms of the MIT License.

remote_bootstrap_modal's People

Contributors

glaucocustodio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

remote_bootstrap_modal's Issues

Dúvida sobre Link

Olá, gostaria de saber se existe a possibilidade de carregar um layout de edição. Por exemplo:

<%= link_to 'EDITAR', edit_client_path(@client), class: 'btn btn-primary btn-block', data: { modal: true } %>

Para o new_client_path eu consegui:

<%= link_to 'CADASTRAR', new_client_path, class: 'btn btn-primary btn-block', data: { modal: true } %>

O clients_controller:

before_action :set_client, only: [:show, :edit, :update, :destroy]

def new
    @client = Client.new
    @client.build_user
    # Adiciona suporte a adição via modal
    respond_modal_with @client
end

def edit
    respond_modal_with @client, location: edit_client_path
end

def set_client
    @client = Client.find(params[:id])
end

Teria ideia do que pode estar ocorrendo, ou poderia ajudar com um exemplo para o caso de abrir um modal para editar um formulário?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.