html_ruby 谐音

谐音

_nav.erb
<header>
  <nav class="nav-bar">
    <a href="/">home</a>
    <% if current_user %>
      <form class="button-link" method="post" action="/sessions">
          <input type="hidden" name="_method" value="delete">
          <button id="logout-button" type="submit">Logout</button>
      </form>
    <% else %>
      <a href="/sessions/new">login</a>
      <a href="/users/new">register</a>
    <% end %>
  </nav>
</header>
_logged_out.erb
<a href="/users/new">Register</a>
<a href="/sessions/new">Login</a>
_logged_in.erb
<a href="/users/<%= session[:user_id] %>"><%= display_name %></a>
<form action="/sessions" method="post">
  <input type="hidden" name="_method" value="delete">
  <input type="submit" value="Logout">
</form>
_error.erb
<% if @errors %>
  <% @errors.each do |error| %>
    <span class="error"><%= error %></span>
  <% end %>
<% end %>
_debug.erb
  <p>**************************************</p>
  <p>Params = <%= p params.inspect %></p><br>
  <p>Session = <%= p session.inspect %></p>
  <p>**************************************</p>

html_ruby _nav.html.erb

application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Overtime</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>

<div class="container">
	<div class="row">
		<div class="col-md-12">
      <%= render 'shared/nav' %>
      <%= yield %>
    </div>
  </div>
</div>

</body>
</html>
application.css.scss
@import 'bootstrap-sprockets';
@import 'bootstrap';
@import 'posts.scss';

.custom-nav {
  margin-top: 70px;
}
_nav.html.erb
<ul class="custom-nav nav nav-tabs">
	<li class="active">
		<a href="#">Home</a>
	</li>
	<li>
		<a href="#">Profile</a>
	</li>
	<li class="disabled">
		<a href="#">Messages</a>
	</li>
	<li class="dropdown pull-right">
		 <a href="#" data-toggle="dropdown" class="dropdown-toggle">Dropdown<strong class="caret"></strong></a>
		<ul class="dropdown-menu">
			<li>
				<a href="#">Action</a>
			</li>
			<li>
				<a href="#">Another action</a>
			</li>
			<li>
				<a href="#">Something else here</a>
			</li>
			<li class="divider">
			</li>
			<li>
				<a href="#">Separated link</a>
			</li>
		</ul>
	</li>
</ul>

html_ruby index.html.erb

index.html.erb

html.erb
<div class="container">
  



<div class="panel-group" id="accordion">

<% @budgets.each do |budget| %>
<% @total =0 %>


  <div class="panel panel-default">

    <div class="panel-heading">
      <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapse<%=budget.id%>">
        <div class="container">
          <%= budget.id%> - <%= budget.fecha %>
        </div>
        </a>
      </h4>
    </div>

    <div id="collapse<%=budget.id%>" class="panel-collapse collapse">

<div class="container">
            
  <table class="table table-hover">
    <thead>
      <tr>
    
        <th>Producto</th>
        <th>cantidad</th>
        <th>Precio</th>
        <th>Sub Total</th>
      </tr>
    </thead>
    <tbody>
    <% budget.budget_details.each do |detail| %>
      <tr>


        <td><%= detail.product.name %></td>
        <td><%= detail.cant%></td>
        <td><%= number_to_currency(detail.product.price) %></td>
        <td><%= number_to_currency(detail.cant * detail.product.price) %></td>
        <% @total = @total + (detail.cant * detail.product.price) %>
      </tr>
<%end%>
       <tr>
    <td></td>
    <td></td>
    <td>Total</td>
    <td><%= number_to_currency(@total) %></td>
      </tr>
    </tbody>
  </table>
</div>


    </div>
  </div>


<%end%>

</div>


</div>




html_ruby 示例主题设置

示例主题设置

settings.html.erb
<!-- /my_theme/views/admin/settings.html.erb -->
<div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title"><%= t('.top_offer', default: 'Top Offer') %></h3>
        </div>
        <div class="panel-body">
            <div class="form-group">
                <label><%= t('.top_offer_product', default: 'Offer Product') %></label><br>
                <%= select_tag "theme_option[top_offer]", options_from_collection_for_select(post_type.posts.public_posts.decorate, :id, :the_title, current_theme.get_option('top_offer')), include_blank: true, class: 'form-control' %>
            </div>

            <div class="form-group">
                <label><%= t('.top_offer_image', default: 'Offer Image') %></label><br>
                <%= hidden_field_tag "theme_option[top_offer_image]", current_theme.get_option('top_offer_image'), class: 'form-control input_upload', 'data-dimension' => '275x395' %>
            </div>
            <div class="form-group">
                <label><%= t('.top_offer_percentage', default: 'Percentage Disccount') %></label><br>
                <%= text_field_tag "theme_option[top_offer_percentage]", current_theme.get_option('top_offer_percentage', 0), class: 'form-control number' %>
            </div>
        </div>
    </div>

html_ruby 验证授权控制器

验证授权控制器

application_controller.rb
#application controller

  def authenticate_user
    redirect_to new_session_path, alert: 'please sign in' unless user_signed_in?
  end

  def user_signed_in?
    session[:user_id].present?
  end
  helper_method :user_signed_in? # adding this line makes this mehtod accessible
                                 # in view files. Because this method is in the
                                 # ApplicationController then it's accessible to
                                 # all views.

  def current_user
    @current_user ||= User.find(session[:user_id]) if user_signed_in?
  end
  helper_method :current_user
cancan_ablility.rb
#cancan的ability的权限设置,只要在这一个文件里修改就可以了

class Ability
  include CanCan::Ability

  # CanCanCan will automatically instantiate an Ability object with every
  # request. It will just expect that you have a method in your controller named
  # `current_user` which we do.
  def initialize(user)

    # it's highly recommend that you start with this line because `user` will
    # be nil if the user is not signed in so it would be ncie to have `user`
    # variable point to a new User object if it's nil so we can easily compare
    user ||= User.new

    # :manage refers to doing any action on the question object: :read, :delete
    # :edit, :update...etc
    can :manage, Question do |q|
      q.user == user
    end

    can :delete, Answer do |a|
      a.user == user || a.question.user == user
    end

    if user.admin?
      can :manage, :all
    else
      can :read, :all
    end

    # if you want to be more specific you could define individual actions
    # can :edit, Question do |q|
    #   # ..
    # end

    # Define abilities for the passed in user here. For example:
    #
    #   user ||= User.new # guest user (not logged in)
    #   if user.admin?
    #     can :manage, :all
    #   else
    #     can :read, :all
    #   end
    #
    # The first argument to `can` is the action you are giving the user
    # permission to do.
    # If you pass :manage it will apply to every action. Other common actions
    # here are :read, :create, :update and :destroy.
    #
    # The second argument is the resource the user can perform the action on.
    # If you pass :all it will apply to every resource. Otherwise pass a Ruby
    # class of the resource.
    #
    # The third argument is an optional hash of conditions to further filter the
    # objects.
    # For example, here the user can only update published articles.
    #
    #   can :update, Article, :published => true
    #
    # See the wiki for details:
    # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
  end
end
question_controller.rb
#question controller

before_action :authenticate_user, except: [:index, :show]
before_action :find_question, only: [:edit, :update, :destroy, :show]
before_action :authorize_access, only: [:edit, :update, :destroy]

#:authenticate_user(用户不登陆只可以看问题show和index) 必须要登陆才可以create,delete和update问题,否则只能看
#:authorize_access(用户只可以修改自己的问题)要有权限才可以对于对问题edit,update和destroy,自己问题才可以自己修改和删除

  private
  def question_params
    params.require(:question).permit([:title, :body])
  end

#put this method in application controller
  def authenticate_user
    redirect_to new_session_path, alert: 'please sign in' unless user_signed_in?
  end

  def find_question
    @question = Question.find params[:id]
  end

  def authorize_access
    unless can? :manage, @question
      # head :unauthorized # this will send an empty HTTP response with 401 code
      redirect_to root_path, alert: 'access denied'
    end
  end
view.erb
#要有权限才可以显示出来question的edit和delete
<% if can? :manage, @question %>
  <%= link_to 'edit', edit_question_path(@question) %>

  <%= link_to 'delete', question_path(@question),
                        method: :delete,
                        data: { confirm: 'Are you sure?' } %>
<% end %>

#要有权限才可以显示出来answer的delete
<% @question.answers.each do |ans| %>
  <%= ans.body %>
  <% if can? :delete, ans %>
    <%= link_to 'delete', answer_path(ans),
                          method: :delete,
                          data: { confirm: 'are you sure?' } %>
  <% end %>
  <hr>
<% end %>

html_ruby Camaleon CMS创建自己的自定义字段(复杂)

Camaleon CMS创建自己的自定义字段(复杂)

main_helper.rb
# /themes/e_shop/main_helper.rb
module Themes::EShop::MainHelper
  def eshop_extra_custom_fields(args)
      args[:fields][:my_slider] = {
          key: 'my_slider',
          label: 'My Slider',
          render: theme_view('custom_field/my_slider.html.erb'),
          options: {
              required: true,
              multiple: true,
          },
          extra_fields:[
              {
                  type: 'text_box',
                  key: 'dimension',
                  label: 'Dimensions',
                  description: 'Crop images with dimension (widthxheight), sample:<br>400x300 | 400x | x300 | ?400x?500 | ?1400x (? => maximum, empty => auto)'
              }
          ]
      }
    end
  end
config.json
// config/config.json
{
  ...
  ...
  "hooks": {
    "extra_custom_fields": ["eshop_extra_custom_fields"]
  }
}
_myslider.html.erb
#/themes/e_shop/views/custom_field/_my_slider.html.erb
<div class="group-input-fields-content" data-callback-render="render_my_custom_slider">
    <div class="form-group">
        <label>Image:</label>
        <div class="input-group">
            <input data-dimension="<%= field.options[:dimension] %>" data-versions="<%= field.options[:versions] %>" data-thumb_size="<%= field.options[:thumb_size] %>" type="url" name="<%= field_name %>[<%= field.slug %>][values][][image]" class="data-error-place-parent image_field form-control <%= "required" if field.options[:required].to_s.to_bool %>"/>
            <span class="input-group-addon btn_upload" onclick="load_upload_image_field($(this).prev());"><i class="fa fa-upload"></i> <%= t('camaleon_cms.admin.button.upload_image')%> <%= "(#{field.get_option('dimension')})" if field.get_option('dimension').present? %></span>
        </div>
    </div>
    <div class="clearfix">
        <div class="form-group">
            <label>Title: </label>
            <input placeholder="Title" type="text" name="<%= field_name %>[<%= field.slug %>][values][][title]" class="title_field translatable form-control required"/>
        </div>
        <div class="form-group">
            <label>Description: </label>
            <textarea placeholder="Description" name="<%= field_name %>[<%= field.slug %>][values][][descr]" class="descr_field form-control translatable required"></textarea>
        </div>
    </div>
</div>
<script>
    function render_my_custom_slider(panel, values){
        values = values && typeof values == 'object' ? values : $.parseJSON(values || '{}');
        panel.find('.descr_field').val(values['descr']);
        panel.find('.title_field').val(values['title']);
        panel.find('.image_field').val(values['image']);
        panel.find('.translatable').Translatable(ADMIN_TRANSLATIONS);
    }
</script>

html_ruby 全球图标助手

全球图标助手

new.html.erb
<% content_for :navigation do %>
  <%= render "shared/primary_nav", locals: {} %>
<% end %>

<% content_for :market_countdown do %>
  <%= render "shared/market_countdown", locals: { visibility_class: 'visible'} %>
<% end %>

<div id="market-order"></div>

<% content_for :stylesheets do %>
  <script>
  var __ICONS__ = {
    close: '<%= asset_url 'icons/close.svg' %>',
    badge: '<%= asset_url 'icons/badge.svg' %>',
    premium: '<%= asset_url 'icons/premium.svg' %>',
    plus: '<%= asset_url 'icons/plus.svg' %>',
    minus: '<%= asset_url 'icons/stepper-minus.svg' %>',
    inventory: '<%= asset_url 'icons/inventory.svg' %>'
  };
  </script>
<% end %>

<% content_for :footer do %>
  <%= render "shared/footer" %>
<% end %>

html_ruby RoR笔记

RoR笔记

rails_queries.rb
# schema.rb 
create_table "foo", :force => true do |t|
  t.integer "user_id"
end

# foo_controller.rb
class FooController < ApplicationController
  def something
    # find the first foo with the same user_id as the current user.
    @foo = Foo.first(:conditions => ["user_id = ?", @user.id])
  end
end
rails_notes.rb
class FooController < ApplicationController
  # needed this line in order to make an ajax call to a controller I wrote.
  # was trying to authenticate the request but couldn't.
  # this allowed for it to skip that step and give me the resource.
  skip_before_filter :authorize_action, :only => :get_user_destinations
  
  
end
rails_notes.html.erb
<!-- button to delete an object --> 

<% @foo.each do |f| %>
    <%= button_to 'delete', f, method: :delete %>
<% end %>

html_ruby RoR笔记

RoR笔记

rails_queries.rb
# schema.rb 
create_table "foo", :force => true do |t|
  t.integer "user_id"
end

# foo_controller.rb
class FooController < ApplicationController
  def something
    # find the first foo with the same user_id as the current user.
    @foo = Foo.first(:conditions => ["user_id = ?", @user.id])
  end
end
rails_notes.rb
class FooController < ApplicationController
  # needed this line in order to make an ajax call to a controller I wrote.
  # was trying to authenticate the request but couldn't.
  # this allowed for it to skip that step and give me the resource.
  skip_before_filter :authorize_action, :only => :get_user_destinations
  
  
end
rails_notes.html.erb
<!-- button to delete an object --> 

<% @foo.each do |f| %>
    <%= button_to 'delete', f, method: :delete %>
<% end %>

html_ruby 用于新位置视图的html

用于新位置视图的html

new.html.erb
<html><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" rel="stylesheet" type="text/css">
    <style>
            html, body {
                height: 100%;
                margin: 0;
                padding: 0;
            }
            #map {
                height: 100%;
            }
            .controls {
                margin-top: 10px;
                border: 1px solid transparent;
                border-radius: 2px 0 0 2px;
                box-sizing: border-box;
                -moz-box-sizing: border-box;
                height: 32px;
                outline: none;
                box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
            }
    
            #pac-input {
                background-color: #fff;
                font-family: Roboto;
                font-size: 15px;
                font-weight: 300;
                margin-left: 12px;
                padding: 0 11px 0 13px;
                text-overflow: ellipsis;
                width: 300px;
            }
    
            #pac-input:focus {
                border-color: #4d90fe;
            }
    
            .pac-container {
                font-family: Roboto;
            }
    
            #type-selector {
                color: #fff;
                background-color: #4d90fe;
                padding: 5px 11px 0px 11px;
            }
    
            #type-selector label {
                font-family: Roboto;
                font-size: 13px;
                font-weight: 300;
            }
            #target {
                width: 345px;
            }
        </style>
  </head><body>
    <div class="navbar navbar-default navbar-static-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-ex-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#"><span>TravelBuddy</span></a>
        </div>
        <div class="collapse navbar-collapse" id="navbar-ex-collapse">
          <ul class="nav navbar-nav navbar-right">
            <li class="active">
              <a href="#">Home</a>
            </li>
            <li>
              <a href="#">Contacts</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="section">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <h1 class="text-center">Pick a Location</h1>
          </div>
        </div>
      </div>
    </div>
  <input id="pac-input" class="controls" type="text" placeholder="Search Box">
        <div id="map"></div>
        <script>
            // This example adds a search box to a map, using the Google Place Autocomplete
            // feature. People can enter geographical searches. The search box will return a
            // pick list containing a mix of places and predicted search terms.
        
            // This example requires the Places library. Include the libraries=places
            // parameter when you first load the API. For example:
            // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
        
            function initAutocomplete() {
                function RandFloat(start, end) {
                    return (Math.random() * end) + start;
                }
        
        
        
                var RandLocation = function() {
                    this.lat = RandFloat(-90, 90);
                    this.lng = RandFloat(-180, 180);
                };
                var map = new google.maps.Map(document.getElementById('map'), {
                    center: new RandLocation(),
                    zoom: 13,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                });
        
                // Create the search box and link it to the UI element.
                var input = document.getElementById('pac-input');
                var searchBox = new google.maps.places.SearchBox(input);
                map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
        
                // Bias the SearchBox results towards current map's viewport.
                map.addListener('bounds_changed', function() {
                    searchBox.setBounds(map.getBounds());
                });
        
                var markers = [];
                // Listen for the event fired when the user selects a prediction and retrieve
                // more details for that place.
                searchBox.addListener('places_changed', function() {
                    var places = searchBox.getPlaces();
        
                    if (places.length == 0) {
                        return;
                    }
        
                    // Clear out the old markers.
                    markers.forEach(function(marker) {
                        marker.setMap(null);
                    });
                    markers = [];
        
                    // For each place, get the icon, name and location.
                    var bounds = new google.maps.LatLngBounds();
                    places.forEach(function(place) {
                        var icon = {
                            url: place.icon,
                            size: new google.maps.Size(71, 71),
                            origin: new google.maps.Point(0, 0),
                            anchor: new google.maps.Point(17, 34),
                            scaledSize: new google.maps.Size(25, 25)
                        };
        
                        // Create a marker for each place.
                        markers.push(new google.maps.Marker({
                            map: map,
                            icon: icon,
                            title: place.name,
                            position: place.geometry.location
                        }));
        
                        if (place.geometry.viewport) {
                            // Only geocodes have viewport.
                            bounds.union(place.geometry.viewport);
                        } else {
                            bounds.extend(place.geometry.location);
                        }
                    });
                    map.fitBounds(bounds);
                });
            }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDnPh5hjvbFBhPQ90cSfRFeIJbjllkPzrM&amp;libraries=places&amp;callback=initAutocomplete" async="" defer=""></script>
    

</body></html>