跳到主要內容

發表文章

目前顯示的是 5月, 2018的文章

Gradle sync failed: Failed to find Build Tools revision 26.0.2

新建立的Android app專案發生下面錯誤,怎麼解決? Gradle sync failed: Failed to find Build Tools revision 26.0.2 這是因為Gradle版本不支援的關係,所以就讓點選錯誤提示下面的連結啟動安裝/更新就可以。

Gradle sync failed: Could not determine java version from '9.0.1'.

新建立的Android app專案發生下面錯誤,怎麼解決? Gradle sync failed: Could not determine java version from '9.0.1'. 這是因為找不到java path的關係,所以就讓專案知道路徑就可以。 (File -> Project Structure -> Project) JDK location: 把Use embedded JDK(recommended)打勾 /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home

建立自己第一個gem

1. 先要有https://rubygems.org/帳號 2. 安裝環境必要套件 $ gem update --system $ gem install rubygems-update Fetching: rubygems-update-2.7.6.gem (100%) Successfully installed rubygems-update-2.7.6 Parsing documentation for rubygems-update-2.7.6 Installing ri documentation for rubygems-update-2.7.6 Done installing documentation for rubygems-update after 28 seconds 1 gem installed $ update_rubygems 3. 建立gem資料夾 (voteable_shawn) $mkdir voteable_shawn $cd voteable_shawn $mkdir lib 4. 設定檔 voteable_shawn/voteable_shawn.gemspec Gem::Specification.new do |s|   s.name        = 'voteable_shawn'   s.version     = '0.0.0'   s.licenses    = ['MIT']   s.summary     = "This is a voteable gem example!"   s.description = "The voting gem!"   s.authors     = ["Shawn"]   s.email       = 'shawnkuo67@gmail.com'   s.files       = ["lib/voteable_shawn.rb"]   s.homepage    = 'https://rubygems.org/gems/example'  

解決Ruby升級後發生的has_many NoMethodError: undefined method `name' for nil:NilClass問題

rvm 2.1.4跑起來正常的專案,升級rvm 2.2.2就噴下面錯誤訊息要怎麼修正它呢? https://github.com/shawnkaku/postit-solution.git 補充:下載後要先bundle update json sqlite3 感謝網友 蔡鴻銘 指導 https://github.com/....../active_scaffold/issues/380...... 升級到rails 4.1.16 + ruby 2.2.4 問題就消失了 Step 1:安裝rvm 2.2.4 $ rvm install 2.2.4 $ rvm use 2.2.4 Using /Users/shawnkuo/.rvm/gems/ruby-2.2.4 Step 2: 修改Gemfile source 'https://rubygems.org' ruby '2.2.4' gem 'rails', '4.1.16' Step 3:升級專案套件 $ ruby -v ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin17] $ bundle install Fetching gem metadata from https://rubygems.org/.......... Fetching gem metadata from https://rubygems.org/. Resolving dependencies... Bundler could not find compatible versions for gem "activesupport":   In snapshot (Gemfile.lock):     activesupport (= 4.0.0)   In Gemfile:     sass-rails (~> 4.0.0) was resolved to 4.0.0, which depends on       sprockets-rails (~> 2.0.0) was resolved to

Rails 網站不顯示id的方法

Add Gem. (/Gemfile) 加 gem 到 Gemfile 中 gem 'friendly_id', '~> 5.1.0' gem 'babosa' 安裝套件 bundle install 建立Table ($rails c) rails g friendly_id rails g migration add_slug_to_posts slug:string:uniq rake db:migrate 修改Model (app/models/post.rb) class Post < ActiveRecord::Base   belongs_to :user, foreign_key: :user_id   has_many :comments   has_many :post_categories   has_many :categories, through: :post_categories   has_many :votes, as: :voteable   validates :title, presence: true, length: {minimum: 5}   extend FriendlyId   friendly_id :id, use: :slugged   # 原本是input.to_s.parameterize,但是parameterize只支援   # 英文跟數字,所以改用babosa的to_slug   def normalize_friendly_id(input)     input.to_s.to_slug.normalize.to_s   end   def should_generate_new_friendly_id?     slug.blank? || id_changed?   # slug 為 nil 或 name column 變更時更新   end   def slug_candidates     [ :id, [:id, :title]]   end end 使用friendly套件查找 (config/initializers/friendly_id.rb) config.us

has_secure_password

資料庫內雖然儲存密碼的欄位是“ password_digest ”,但是實際要把它的欄位名稱當成“ password ”來使用。 2.1.2 :001 > user = User.find_by username: "BBB"   User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."username" = 'BBB' LIMIT 1  => # 2.1.2 :002 > exit kuruwateki-MacBook-Air:postit-solution shawnkuo67$ rails c Loading development environment (Rails 4.0.0) 2.1.2 :001 > user = User.find_by username: "BBB"   User Load (0.7ms)  SELECT "users".* FROM "users" WHERE "users"."username" = 'BBB' LIMIT 1  => # 2.1.2 :002 > user. password = 'abcdef'  => "abcdef" 2.1.2 :003 > user.save    (0.2ms)  begin transaction Binary data inserted for `string` type on column ` password_digest `   SQL (6.0ms)  UPDATE "users" SET "password_digest" = ?, "updated_at" = ? WHERE "users"."id" = 2  [["