Hello, I have a Category, a Subcategory and a Product model.
I have:
Category has_many Subcategories
Subcategory has_many Products
Subcategory belongs_to Category
Product belongs_to Subcategory
Is there a way to have something like
Category has_many Projects through Subcategories
?
The 'normal' rails way wouldn't work because "subcategory" doesn't belongs to product so product does not have a subcategory_id field. Instead, I need the query to be something like
SELECT * FROM products WHERE id IN category.subcategory_ids
Is there a way to do that?
Thanks,
Nicolás Hock Isaza
which database should I use, if my application is going to be in multiple languages (including Chinese, Japanese etc)? In other words, is MySQL better or worse than Postgres to handle unicode etc? (these are the only two databases my hosting company has)
Also, which language is better for handling unicode? PHP or Ruby/Rails?
I am looking for an alternative to acts_as_solr or thinkingsphinx for fulltext search in my Rails app. Came across searchlogic. Does it support indexing? I am planning to host my app on heroku and I want an alternative because heroku charges for Websolr. I am aware of the alternative way of using texticle or acts_as_tsearch but i want to use searchlogic for its features.
I'm trying to get IronRuby onRails running with iis7 server 2k8 and can only get as far as it cannot load the assembly 'IronRuby.Rack' (Screen Shot: http://grab.by/3VZm) has anyone gotten this working? Any tips you can give me?
Thanks,
-CJ
Given a very simple ruby script:
child = fork do
system 'sleep 10000'
end
5.times do
sleep 1
puts "send kill to #{child}"
Process.kill("QUIT", child)
end
QUIT signal is just lost. Where does it go? Something with default handler which just ignores it?
I'm writing a little client using Ruby and Savon. The interface changed significantly from version 0.7 to 0.8.x. All my calls don't work anymore :-(.
How can I pass on a local member variable.
Please see the example, @userName and @userPassword are not defined within the block.
begin
@response = @authentication_svc.request :wsdl, "AuthenticateUser" do
http.headers["SOAPAction"] = "AuthenticateUser"
soap.body = "#{@userName}#{@passwd}"
end
rescue Savon::SOAP::Fault = e
@last_soap_error = e.message
end
I am writing a RubyonRails app and I want a method to be called every time the database is modified. Is it possible to do this without inserting a method call in every location where the database is modified?
Which of the following technology is easy to learn and fun for developing a website? If you could only pick one which would it be and why
Clojure/Compojure+Ring/Moustache+Ring
Groovy/Grails
Python/Django
Ruby/Rails
Turbogear
Cappuccino or Sproutcore
Javascript/jQuery
Hi,
I am trying to make a multi-dimensional array of characters in ruby, and this works, but is there a more elegant way?
def initialize(text)
@map = Array.new
i = 0
text.split("\n").each do |x|
@map[i] = x.scan(/./)
i += 1
end
#@map = text
end#constructor
I need to validate form on client-side and I was wondering if there is a rails plugin which will help me in this task (maybe it will build javascript needed to validate certain model)?
I am using gsub in Ruby to make a word within text bold. I am using a word boundary so as to not make letters within other words bold, but am finding that this ignores words that have a quote after them. For example:
text.gsub(/#{word}\b/i, "<b>#{word}</b>")
text = "I said, 'look out below'"
word = below
In this case the word below is not made bold. Is there any way to ignore certain characters along with a word boundary?
I have a rails controller file that is too large (~900 lines - api_controller). I'd like to just split it up like something like this:
api_controller.rb
api_controller_item_admin.rb
api_controller_web.rb
I don't want to split into multiple controllers. What would be the preferred way to do this? Could I just require the new parts at the end? like:
require './api_controller_item_admin'
require './api_controller_web'
If you use haml as rails view template, you can write portion of your page using markdown by using the ":markdown" filter.
Is is possible to do the same using erb?
I need to install a plugin like this:
script/plugin install git://github.com/apotonick/cells.git
and it just creates a new empty folder in the plugins dir, "cells"
(i use eclipse and rails)
Is that a bad question, i dont get it?(-6 votes)
I am trying to write excel file by using ruby 1.9 spreadsheet version 0.6.4.1 on windows.
Everything is going ok,
until I get to the book.write statement
when I write book.write "c:/spreadsheet/excel-file.xls
I keep getting the following error
No such file or directory - c:/spreadsheet/excel-file.xls
Can anyone tell me what I should change in this path name?
I want to use selenium test to cover my rails project ! but i just find little documents on selenium test . I want someone to give me some documents for selenium test of all types !like website ,pdf ,text etc. you can sent them to my gmail [email protected] Thank you ,and best regards!
What is the more "rails-like"? If I want to modify a model's property when it's set, should I do this:
def url=(url)
#remove session id
self[:url] = url.split('?s=')[0]
end
or this?
before_save do |record|
#remove session id
record.url = record.url.split('?s=')[0]
end
Is there any benefit for doing it one way or the other? If so, why? If not, which one is generally more common?
Hi,
This is a quick question. I have the following ruby code, which works fine.
def add_zeros number, zeros
number = number.to_s
zeros_to_add = zeros - number.length
zeros_to_add.times do
number = "0#{number}"
end
number
end
But if I replace
number = "0#{number}"
With
number.insert(0, "0")
Then I get TypeError: can't modify frozen string, does anyone know why this is?
Hi,
I have started learning Ruby and just tried out my first hello world program in NetBeans IDE. I have one doubt, I can see that the new project wizard created set of package structure. It had one "Rakefile" in it. What does that mean and what is the use of it?
Thanks,
Bragaadeesh.
I'm a little confused about scope of variables, in ruby I wrote a test program:
class Test
attr_reader :tester
def initialize(data)
@tester = data
end
def getData
tester
end
end
puts Test.new(11).getData
now this works fine, the attr_reader, but my confusion is that since I've define attr_reader :tester then why can't I go tester = data rather then @tester = data, because when retrieving the data in getData I only have to write tester and not @tester
I know you can do this with virtual attributes, but what if the column actually exists?
For example, my model has a raw_topic column. When raw_topic is set, I want artist and song_title to be set based off of raw_topic's contents. Ideally, I'd like to override the raw_topic= method, but rails doesn't seem to like that.
What's the proper way of doing this? Is a callback the only way?
I'm trying to prevent users from uploading (accidentally or maliciously) very large files to my website.
I have nginx max_client_body_size set to 4M, but if a file larger than this is uploaded, then it uploads the entire file before returning 413 (entity too large).
I want to make nginx check the Content-Length header, so that it rejects the request before it's uploaded.
Alternatively, a Rails solution would also be acceptable.
Any help appreciated.