recentpopularlog in

kme : rails   166

« earlier  
apache - Apache2 ProxyPass for Rails App Gitlab - Stack Overflow
The problem I was having was a route that matched "/icons," and it was trying to serve GitLab's 'icons-[HASH].svg' from the filesystem, which resulted in a 404.
webmaster  gitlab  apache  rails  proxy  config  reference 
december 2019 by kme
riseuplabs / crabgrass · GitLab | https://0xacab.org/
Crabgrass is a web application designed for activist groups to be better able to collaborate online. Mostly, it is a glorified wiki with fine-grain control over access rights.
ruby  rails  wiki  collaboration  activism  webapp  samplecode  webdevel 
february 2019 by kme
Nokogiri install fails because of missing lzma symbols in self built libxml2 · Issue #1119 · sparklemotion/nokogiri · GitHub
Ran into this problem attempting to install veewee, and something about the libxml2 2.9.4 that comes with Nokogiri (it's bundled "[b]ecause Nokogiri needs to be compiled and dynamically linked against both libxml2 and libxslt, it has gained a reputation for being complicated to install.")
installed the current version of Xcode
$ sudo port install libxml2 libxslt
$ bundle config build.nokogiri --use-system-libraries
ruby  rails  rubyonrails  library  errormessage  libxml2  macos  solution 
june 2016 by kme
/bin/recykl » Blog Archive » Visualize your Rails schema
Changes required for Rails 4:
--- uml_dumper.rb.orig 2014-07-31 08:54:53.000000000 -0400
+++ uml_dumper.rb 2014-07-31 08:50:36.000000000 -0400
@@ -13,7 +13,8 @@
# A list of tables which should not be dumped to the schema.
# Acceptable values are strings as well as regexp.
# This setting is only used if ActiveRecord::Base.schema_format == :ruby
- cattr_accessor :ignore_tables
+ #cattr_accessor :ignore_tables
+ mattr_accessor :ignore_tables
@@ignore_tables = []

def self.dump(connection=ActiveRecord::Base.connection, stream=STDOUT)
@@ -60,8 +61,10 @@
@connection.tables.sort.each do |tbl|
next if ["schema_info", ignore_tables].flatten.any? do |ignored|
case ignored
- when String: tbl == ignored
- when Regexp: tbl =~ ignored
+ when String
+ tbl == ignored
+ when Regexp
+ tbl =~ ignored
else
raise StandardError, 'ActiveRecord::UmlDumper.ignore_tables accepts an array of String and / or Regexp values.'
end
@@ -221,7 +224,8 @@
<XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/>
</XMI.header>
<XMI.content>
-<UML:Model xmi.id="UMLProject.1" name=#{@connection.current_database.inspect}>
+<!-- UML:Model xmi.id="UMLProject.1" name="(hash){@connection.current_database.inspect}" -->
+<UML:Model xmi.id="UMLProject.1" name="uml_dumper">
<UML:Namespace.ownedElement>
<UML:Model xmi.id="UMLModel.6" name="Design Model">
<UML:Namespace.ownedElement>
database  uml  modeling  visualization  rails  schema  dba  staruml 
july 2014 by kme
collect with index? - Ruby Forum
Or in Ruby 1.9 it's simply:

>> ary = ["cat", "dog", "pig"]
=> ["cat", "dog", "pig"]
>> ary.each_with_index.collect { |animal, index|
"#{animal} number #{index + 1}"
}
=> ["cat number 1", "dog number 2", "pig number 3"]
ruby  rails  solution  syntax  listcomp  array 
july 2014 by kme
rails, How to build table in helper using content_tag? - Stack Overflow
Solution to my actual problem:
Actually you are only missing a plus between content tags, you can find a similar question here
(I was passing them as separate *arguments*, expecting content_tag to just figure it out).

But here's another interesting solution using .collect():
def display_standard_table(columns, collection = {})

thead = content_tag :thead do
content_tag :tr do
columns.collect {|column| concat content_tag(:th,column[:display_name])}.join().html_safe
end
end

tbody = content_tag :tbody do
collection.collect { |elem|
content_tag :tr do
columns.collect { |column|
concat content_tag(:td, elem.attributes[column[:name]])
}.to_s.html_safe
end

}.join().html_safe
end

content_tag :table, thead.concat(tbody)

end
rails  erb  template  view  helper  ruby  webdevel  solution 
july 2014 by kme
Rails - Redirect 404 Page RecordNotFound - I create things.
Could this be considered a best practice? Shouldn't it return a 302 Moved Permanently or whatever?
error404  rails  errorhandling  webdevel  bestpractice 
july 2014 by kme
ruby on rails - raise ActiveRecord::RecordNotFound (or any 404 status) for invalid date - Stack Overflow
def show
begin
end_range = Date.new(...)
rescue ArgumentError
# Invalid date
raise ActiveRecord::RecordNotFound
end
rescue ActiveRecord::RecordNotFound
render(:partial => 'not_found', :layout => 'application', :status => :not_found)
end


Several other examples in the accepted answer.
rails  webdevel  activerecord  controller  errormessage  errorhandling  solution 
july 2014 by kme
unit testing - Ruby on Rails: Running Tests - Stack Overflow
When I want to run all my unit tests, I run rake test:units. To run all my functional tests, I run rake test:functionals. If I want to run all the test cases in one file, I run

ruby test/unit/username_test.rb

A few people have been telling me I should run rake instead such as

rake test:units TEST=test/unit/username_test.rb



The answer is that rake sets up the appropriate environment (rather than clobbering your production data, for instance)
rails  testing  rake  newbie  question  solution 
july 2014 by kme
jetthoughts/yaml_db · GitHub
gem 'yaml_db', github: 'jetthoughts/yaml_db'

Fixes the
NoMethodError: undefined method `[]=' for #<ActiveRecord::Result:0x007fc6104bc1b0>
error that you get from https://github.com/ludicast/yaml_db
yaml  dba  database  rails  backup  migration  solution 
july 2014 by kme
ruby on rails - yaml_db Not Working When Dumping the Database - Stack Overflow
plee@sos:~/rubyonrails/blog$ rake db:dump
rake aborted!
Don't know how to build task 'db:dump'

(See full trace by running task with --trace)
rails  rake  yaml  database  dba  errormessage  maybesolution 
july 2014 by kme
ludicast/yaml_db · GitHub
YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.

This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.

Any database that has an ActiveRecord adapter should work. This gem is now Rails 3 only. For Rails 2, clone and checkout the Rails2 branch.


Note that /this/ is still totally wrong:
rake db:data:dump_dir -> Dump contents of database to curr_dir_name/tablename.extension (defaults to yaml)
rake db:data:load_dir -> Load contents of db/data_dir into database


What it actually does is creates timestamped subfolder in Rails.root/db, *then* creates .yml files by table name. It completely ignores curr_dir_name, whatever that's supposed to mean.
ruby  rails  gem  backup  testing  yaml  database  dba 
july 2014 by kme
ruby on rails - Why do test:units and test:functionals insist on running in development environment? - Stack Overflow
At the top of the test_helper.rb file I have the code

ENV["RAILS_ENV"] = "test"

If you do not have that line then the system problem would run in the default environment (i.e. development).
rails  troubleshooting  environment 
july 2014 by kme
Add initialization step to Rails 3 boot process only in server mode - Stack Overflow
Way back when I posted this question, Mongoid was experiencing this issue. I reported it here, and it was resolved by wrapping the code in a config.after_initialize block. If Rails isn't initialized, then this block is never called. More information here.
rails  bootprocess  initializer  maybesolution 
july 2014 by kme
Timestamp support for Rails and MySQL/PostgreSQL/Oracle « So far, it’s RoR
:conditions => "timestamp > #{start_time} AND timestamp < #{end_time}")
rails  dateandtime  dba  query  timestamp  reference 
july 2014 by kme
Adding lib to 'config.autoload_paths' in Rails 3 does not autoload my module - Stack Overflow
I place a file name g.rb in side Rails.root/lib folder The file content is like this:

module Google
end

Then I add

config.autoload_paths += %W(#{config.root}/lib #{Rails.root}/app/delayed_jobs)

to my Rails.root/config/application.rb



One answer suggested
require 'mymodule'
include Mymodule


might solve some problems.
rails  bootprocess  maybesolution  ruby  library  autoload  annoyance 
july 2014 by kme
Centos+Apache+passenger+rails: running rails apps from your www folder - Stack Overflow
I had this problem, but I think one of us just goofed and accidentally ran the Rails server as root, which created some temp files that our 'deploy' user couldn't overwrite.
rails  passenger  errormessage  webmaster  maybesolution 
july 2014 by kme
ruby - how to check string is valid date or not in rails - Stack Overflow
require 'date'
begin
Date.parse("31-02-2010")
rescue ArgumentError
# handle invalid date
end
ruby  rails  datetime  webdevel  dateandtime  solution 
july 2014 by kme
Rails & Sqlite question - comparing dates to db timestamps - Stack Overflow
The best practice is to use to_s(:db) for referencing datetimes in a database in Rails. Try:
ruby  rails  datetime  activesupport  timezone  bestpractice  webdevel 
july 2014 by kme
ruby - Default TimeZone with ActiveSupport (without Rails) - Stack Overflow
I wanted to know how to include ActiveSupport:TimeWithZone in an initializer that didn't have access to the whole Rails environment yet. I think this was how:
irb -r 'rubygems'
ruby-1.8.7-p174 > require 'active_support'
ruby-1.8.7-p174 > require 'active_support/time_with_zone'
ruby-1.8.7-p174 > Time.zone
ruby-1.8.7-p174 > nil
rails  activesupport  dateandtime  fuckina  solution 
july 2014 by kme
Working with time zones in Ruby on Rails — Elabs
ActiveSupport::TimeWithZone.new(nil, Time.zone, DateTime.parse("2012-03-25 03:29"))
ruby  activesupport  rails  timezone  time  bestpractice  reference 
july 2014 by kme
Making Configuration Files with YAML: Revised | Innovative Thought
Then, I create a new file called load_config.rb within the /config/initializers directory. You can name the file whatever you want – that’s just what I call it. This is where the actually YAML loading is going to happen – and this is what it looks like:

raw_config = File.read(RAILS_ROOT + "/config/config.yml")
APP_CONFIG = YAML.load(raw_config)[RAILS_ENV]
yaml  configfile  ruby  rails  webdevel  solution 
july 2014 by kme
How to comment lines in rails html.erb files? - Stack Overflow
ruby on rails notes has a very nice blogpost about commenting in erb-files

the short version is

to comment a single line use

<%-# commented line -%>

to comment a whole block use a if false to surrond your code like this

<% if false %>
code to comment
<% end %>
rails  erb  comments  webdevel  devel  solution 
july 2014 by kme
Showing Ruby, Rails and git info in your app — ariejan de vroom
# config/initializers/git_revision.rb
module AppName
REVISION = `git log --pretty=format:'%h' -n 1`
end

This will expose the current short SHA in your application's namespace:

AppName::REVISION
=> "ac6d3a0"
git  rails  webdevel  versioninfo  troubleshooting  solution 
july 2014 by kme
ruby - Rails 4 calling model from different controller - Stack Overflow
This pretty much described the problem I was having. What I was having difficulty wrapping my head around was the fact that the view logic didn't (seem to) just have access to whatever class variables existed in the controller. I was even getting errors trying to invoke (private) class methods to assign values to @project_commits.

I solved the issue I was having (pulling data from another model into a controller/view) by calling a private method with before_filter. Nothing in application_controller.rb, but the actual controller that was trying to render the data.
rails  controller  notheproblemihad  reference  webdevel  devel 
july 2014 by kme
ruby on rails - Calling a method from another controller - Stack Overflow
Not the problem I had. I solved the issue I was having (pulling data from another model into a controller/view) by calling a private method with before_filter.
rails  controller  reference  devel 
july 2014 by kme
How do I call controller/view methods from the console in Rails? - Stack Overflow
To call helpers, use the helper …hmm… helper.

$ ./script/console
>> helper.number_to_currency('123.45')
=> "R$ 123,45"
rails  helper  console  debugging  devel  controller  solution 
july 2014 by kme
ruby - Rails 4 migration: how to reorder columns - Stack Overflow
Except I don't think that SQLite supports whatever Rails is doing under the hood.
You can call change_column, but you have to repeat the column type (just copy and paste it from your other migration):

def up
change_column :your_table, :some_column, :integer, after: :other_column
end

Or if you have to reorder multiple columns in one table:

def up
change_table :your_table do |t|
t.change :some_column, :integer, after: :other_column
# ...
end
end

change_column calls ALTER TABLE under the hood. From the MySQL documentation:

You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table.
almostsolution  rails  migration  db  devel 
july 2014 by kme
How to define custom configuration variables in rails - Stack Overflow
Rails.configuration.custom_config_variable = :my_config_setting

Also (probably):

Dude, simple: Path: config/environments/production.rb Config: config.whatever = false Access it anywhere: Rails.configuration.whatever
rails  configfile  deployment  maybesolution 
july 2014 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read