ruby Codiing片段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Codiing片段相关的知识,希望对你有一定的参考价值。
Codiing snippets db
User
id - int
name - string (255)
email - string (255)
password - string (255)
snippets Snippet
id - int
name - string (255)
description - text
short_url - string (Random 8 character string) (index)
tags - string (php,laravel,ruby) - Loop in array.
categories Category
id - int
name - string (255) (html, css, js) - Este campo guardaria uno de esos 3 valores.
categories_snippets
Esta tabla es "pivot". Guarda la relacion entre "categories" y "snippets"
id - int
snippet_id - int
category_id - int
codes Code
id - int
snippet_id - int
type - string - (html, css, js) - Este campo guardaria uno de esos 3 valores
code - text
comments Comment
id - int
user_id - int
snippet_id - int
comment - text
likes Like
id - int
user_id - int
snippet_id - int
notifications Notification
id - int
type - string - (comment, like) - Este campo guardaria uno de estos 2 valores
auth_user_id - int
receiver_user_id - int
comment_id - int
# Creating the codiing snippets app
rails new codiing-snippets --skip-bundle --skip-turbolinks --database=postgresql
# Add devise gem
bundle install
rails generate devise:install
# to change devise views
rails g devise:views
rake db:create
rails g devise User
rake db:migrate
# add seed test
# User.create name: 'User 1', email: 'email1@email.com', password: 'password 1'
rake db:seed
rake db:migrate
# add name attribute
rails g migration add_attributes_to_users name:string
rails g migration add_attributes_to_events user_id:integer
rake db:migrate
# current user on erb
# <%= current_user.email %>
--
CarrierWave
rails generate uploader Avatar
rails g migration add_avatar_to_users avatar:string
rake db:migrate
# add mount to user model
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
# registration devise new
<div class="field">
<%= f.label :avatar %><br />
<%= f.file_field :avatar %>
</div>
# Create a new registation controller no generate - add name and avatar
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :avatar)
end
def account_update_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password, :avatar)
end
end
----------
# Create routes
resources :users do
resources :categories , only: [:new, :create, :index, :show, :edit, :update, :destroy] do
resources :snippets , only: [:new, :create, :index, :show, :edit, :update, :destroy] do
resources :comments , only: [:new, :create, :index, :show, :edit, :update, :destroy]
resources :tags , only: [:new, :create, :index, :show, :edit, :update, :destroy]
resources :likes , only: [:new, :create, :index, :show, :edit, :update, :destroy]
end
end
end
---------
# Create models
rails g resource Category name:string
rails g resource Snippet name:string description:text short_url:string tags:string
# Create join table
rails g migration CreateJoinTableCategorySnippet category snippet
rake db:migrate
rails g migration CreateJoinTableSnippetUser snippet user
rails g controller users
----------
# private
def set_user
# @user = User.find params[:user_id]
@user = User.find current_user
end
before_action :set_user
--------
Console
u = User.find_by_id(1)
u.categories
c = Category.find_by_id(9)
c = Category.find(9)
Branches
git
git clone git@github.com:buddylove954/Hackathon.git
cd hackaton
git checkout frontend
-------
git commit
git push frontend
-------
hackIron
#change to master branch
git checkout master
git pull git@github.com:buddylove954/hackIron
git pull --force origin master
git push origin master
priscillarodriguez@Priscillas-MacBook-Pro-2:~/desktop/hackiron(master)$ export FB_API_SECRET='345070248f078f93b39c92c79c818d3a'
priscillarodriguez@Priscillas-MacBook-Pro-2:~/desktop/hackiron(master)$ echo $FB_API_SECRET
345070248f078f93b39c92c79c818d3a
priscillarodriguez@Priscillas-MacBook-Pro-2:~/desktop/hackiron(master)$ export KAIROS_API_SECRET='ee01180df7b7a10f05305e39e9adb565'
priscillarodriguez@Priscillas-MacBook-Pro-2:~/desktop/hackiron(master)$
<li><%= link_to(category.name, category_snippets_path(category_id: category.id)) %></li>
before_filter :authenticate_user!, except: [:index]
many to many used join tables
------------
Heroku
git status
git add .
git commit -m "add Seed Dump gem"
git push heroku master
# db:seed optional
heroku run rake db:migrate db:seed
#check apps
heroku apps
#check errors
heroku logs --tail
heroku run rails console
heroku run rake geocode:all CLASS=Startup
-------------------
Geocoder
rails generate migration AddLatitudeAndLongitudeToStartups latitude:float longitude:float
full_street_address
rake geocode:all CLASS=Startup
--------
favorites
----------
index
new
create
show
edit
update
destroy
resources :users do
resources :categories , only: [:new, :create, :index, :show, :edit, :update, :destroy] do
resources :snippets , only: [:new, :create, :index, :show, :edit, :update, :destroy] do
resources :comments , only: [:new, :create, :index, :show, :edit, :update, :destroy]
resources :tags , only: [:new, :create, :index, :show, :edit, :update, :destroy]
resources :likes , only: [:new, :create, :index, :show, :edit, :update, :destroy]
end
end
end
# it puts api at the beginning in the rake routes
namespace :api do
get '/matches' => 'matches#wins'
get '/matches/:faction' => 'matches#factions'
get '/players/:player_id' => 'players#show'
get '/players/:player_id/:faction' => 'players#show'
end
users
categories
snippets
tags
comments
like
------------
rails g resource Event name:string description:text url:string date:datetime location:string
rails g resource Startup name:string description:text url:string
rails g resource CoWorkingSpace name:string description:text url:string price:string
rails g resource Job name:string description:text location:string url:string price:string
rails g model Favorite
以上是关于ruby Codiing片段的主要内容,如果未能解决你的问题,请参考以下文章