I'm messing around with a test/exercise project just to understand Rails better.
In my case I have three models: Shop, User and Product.
A Shop can be of three types: basic, medium, large. Basic can have 10 Products maximum, medium 50, large 100.
I'm trying to validate this kind of data, the type of Shop and check how many products it...
Is there a pattern to refactor such a construct into a readable single line?
def show_section
@news = News.all_active
@news = @news.where(:section => params[:section]) unless params[:section] == "all"
@news = @news.all
end
I use Rails 3 and Ruby 1.9.2
...
I am making a gem, but how to test(not unit test, just make sure the program is right) it ?
Need I pack it and run every time when I modify it?
...
When try to run my Rails application (either by running rake, ./script/console or ./script/server), I get src/tcmalloc.cc:353] Attempt to free invalid pointer or Segmentation fault (depending on if running on REE or MRI). It's been running just fine till yesterday, when with no particular reason (did not install any new gems, did not upd...
I have a helper method which checks whether the collection of objects is empty? If not then it checks each one to make sure that the the existing event_id is not the @current_event.id.
Here is my crack at it:
def build_answers(question)
if question.answers.empty?
return question.answers.build
else
question.answers.each do |...
I have to following problem:
If i want to follow the Rails naming convention i have to use the plural version of the model's name as my controller name.
Example:
rails g scaffold_controller Content
In this case i have a model(Content) and the previous command is going to generate a controller with the name Contents.
So what if I ha...
I am following through the RailsCasts episode on PayPal security. I am try to port this code to C# and am using OpenSSL.NET
Also is it possible to do this without using the OpenSSL wrapper library as that uses some unmanaged code?
The ruby code that I am trying to port is this:
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7:...
I this model:
class Bunny < ActiveRecord::Base
attr_accessor :number
validates_presence_of :number
validates_numericality_of :number
end
Whenever I submit a form to create this model I get the following error:
undefined method `number_before_type_cast' for #<Bunny:0x103624338>
...
I found a similar post here but I can't solve the problem anyway.
I got this
/home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII)
/home/fra/siti/Pensiero/db/seeds.rb:32: invalid multibyte char (US-ASCII)
/home/fra/siti/Pensiero/db/seeds.rb:32: syntax error, unexpected $end, expecting ')'
... ed il valore della vita,...
I am trying to convert a temperature from Fahrenheit to Celsius:
puts 'Convertir grados Fahrenheit a Celcius'
STDOUT.flush
x = gets.chomp
aprox = (x * 100.0).round(2) / 100.0
resultado = (aprox-32)/1.8
puts resultado
I use the correct formula for converting Fahrenheit to Celcius:
Celsius = Fahrenheit - 32 / 1.8
However, when ...
I have a mixin for which I would like to get a list of all the classes that have included it. In the mixin module, I did the following:
module MyModule
def self.included(base)
@classes ||= []
@classes << base.name
end
def self.classes
@classes
end
end
class MyClass
include MyModule
end
This works pretty well:
...
Ok so i am creating an hash and i need to add the id to the hash..here is my code
h = Hash.new {|h1, k1| h1[k1] = Hash.new{|h2, k2| h2[k2] = []}}
@result, today = [ h, h.dup], Date.today
Request.find_all_by_artist("Metallica", :select => "DISTINCT venue, showdate, LOWER(song) AS song, id").each do |req|
# need to insert the req.id in ...
Hi,
I'm writing a rails application, and I need to name one of my model Test, and inside that model I need a class attribute - when I tried the first one, I couldn't run any UT since Test ceased to be a module - so I ranamed to Tst. I haven't even tried naming a column class - I went with clss. What names would you use? Are there any c...
Hello, new to Ruby on Rails, trying to configure the home page of my application. I don't know what I'm doing wrong, or how to configure the :home controller, but I get this error with this routes.rb file.
Routing Error - No route matches "/"
Here's routes.rb
SchoolCMS::Application.routes.draw do
devise_for :teachers, :admin
res...
Is there a way to simulate Smalltalk's doesNotUnderstand or Ruby's method_missing in Javascript?
...
UPDATE: Question still unanswered. @Alastair_Pitts: Unless I'm missing something, it's a two part question. The second part, "If so, why is this done?" and not been answered.
Believe the question is clear, but if you have any questions -- just let me know. Thanks!
undefined = unknown and is a reference to system based on ternary logi...
I'm storing configuration variables for different environments in the production.rb and development.rb
production.rb
ENV['my_variable'] = 'val1'
development.rb
ENV['my_variable'] = 'val2'
Maybe exists another way to store variables for different environments. What is the best way?
...
I am currently unable to install any gems because I keep getting the follwiing error message
ERROR: While executing gem ... (Errno::E045)
Operation not supported - /home/rocker
I am using sudo command.
I believe the issue is in my gen env has info that is no longer correct
RubyGems Environment:
RUBYGEMS VERSION: 1.3.7
RUBY VERS...
how to embed a bash prompt/terminal inside ruby on rails web page?
how to execute a linux command from the web page, and get the output of the ommand?
...
In Ruby both expressions seem to do similar things:
'it' =~ /^it$/ # 0
'it' =~ /\Ait\Z/ # 0
# but
/^it$/ == /\Ait\Z/ # false
So I an wondering what is the difference between ^-\A and $-\Z and how to choose which one to use?
...