Ruby syntax error, unexpected tIDENTIFIER, expecting end-of-input
This line was messing with my head. The puts doesn’t belong there are all! ruby_tree.visit {|node| puts node.node_name} puts
This line was messing with my head. The puts doesn’t belong there are all! ruby_tree.visit {|node| puts node.node_name} puts
hash = {“name”=>”XYZ”, “address”=>{“street”=>{“street_address”=>””,”city”=>”City name”}}, “form”=>{“id”=>11,”f_name”=>””}, “test”=>””} def remove_blanks hash hash.map do |k, v| v == ” ? nil : [k, v.is_a?(Hash) ? remove_blanks(v) : v] end.compact.to_h end remove_blanks hash #⇒ { # “address” => { # “street” => { # “city” => “City name” # } # }, # “form” => { # “id” … Read more
Actually it’s almost the same: my_key = :name my_hash = { name: ‘Joe’, age: 52 } my_hash[my_key] #=> “Joe” See http://www.ruby-doc.org/core-2.1.1/Hash.html
The money gem uses I18n. You can either add a valid locale or disable I18n: require ‘money’ Money.new(100).format #=> I18n::InvalidLocale: :en is not a valid locale Money.use_i18n = false Money.new(100).format #=> “$1.00”
One thing you can do is set up a separate blog server (let’s say using wordpress) and point the DNS for blog.example.com to the ip address of your blog server. Then you can give individual users accounts on the blog, so that they can upload content. I would suggest using an existing blog engine such … Read more
I would suggest something like this: /\) (?!.*\))(\S+)/ rubular demo Or if you don’t want to have capture groups, but potentially slower: /(?<=\) )(?!.*\))\S+/ rubular demo (?!.*\)) is a negative lookahead. If what’s inside matches, then the whole match will fail. So, if .*\) matches, then the match fails, in other terms, it prevents a … Read more
This type of validation is handled by validates_presence_of. Seems like you’re looking for validates_presence_of :lock_version, on: :update I strongly advise to take a look on http://apidock.com/rails/ActiveRecord/Validations/ClassMethods/validates_presence_of There are plenty of validations in Rails and this is probably the most basic one. http://guides.rubyonrails.org/active_record_validations.html
This was an unpopular question, but I found out how to do what I wanted some time later. I will post the solution for anyone that would like to do what I wanted to accomplish. So I wanted to make an instance of prints into a product page. I set up a control method in … Read more
You can easily do that by using the strftime method, in this case it would be something like this: Time.now.strftime(“%d/%m/%Y %H:%M”) You can find the complete docs here: http://apidock.com/ruby/DateTime/strftime
Login to your mysql and add user (rails_user). Then grant the user privileges to the database you have created for your application beacuse it may happen that you already have the user(rails_user) but the use does not have privileges to the database of your application. then go to database.yml and put the require credentials for … Read more