I have a Property model with a has_many and accepts_nested_attributes_for on a Image model which uses attachment_fu. Updating a Property using the following code results in a database UPDATE for every single image (and each image thumbnail) no matter whether there were changes to it or not.
properties_controller.rb
def update
@pr...
kratos-iii:railsproj zachinglis$ rake db:create
(in /Users/zachinglis/Sites/rails/railsproj)
Couldn't create database for {"adapter"=>"mysql", "host"=>"localhost", "username"=>"root", "password"=>nil, "database"=>"railsproj_development"}, charset: utf8, collation: utf8_general_ci (if you set the charset manually, make sure you have a mat...
if params[:parent_type] == "Order"
parent_id = nil
else
parent_id = params[:parent_id]
end
Would a Ruby person laugh at me for writing it this way? It doesn't seem particularly concise like some Ruby code I've seen.
...
Hay guys, I'm a novice to intermediate RoR programmer. However, I'm not too good on setting up relational database's so i need a hand.
Basically my app is a book club. A user signs up, the user creates a book club based on a book. Other users joins this club and discusses it (like a forum).
I have written a english description of the s...
Sample data:
"iWine","Barcode","Location","Bin","Size","Valuation","Price","StoreName",\
"PurchaseDate","Note","Vintage","Wine","Locale","Country","Region","SubRegion",\
"Appellation","Producer","SortProducer","Type","Color","Category","Varietal",\
"MasterVarietal","Designation","Vineyard","WA","WS","IWC","BG","WE","JR",\
"RH","JG","GV"...
In my main Sinatra controller, I want to debug the params hash after it is POSTed from a form.
I have added:
puts params.inspect
and
set :logging, :true
The params.inspect works if everything goes well. But if an error happens before the controller is executed I'm not getting any information about the error like I would in Rails b...
Suppose I have this HTML:
html = <div>Four score and seven years ago</div>
What's the best way to insert (say) an anchor tag after the word "score"? Note: I want to do this in terms of DOM manipulation (with Hpricot, e.g.) not in terms of text manipulation (e.g., no regexes)
...
I am using Nokogiri 1.3.3 with Ruby 1.8.7 I am trying to match the content of a tag as described in this SO question:
nodeset.xpath("entry/index[. = '#{index.to_s}']/../categories")
Nokogiri raises an exception complaining about the '.' after the bracket. When I replace the '.' with text() it then complains about the second period. ...
I'm looking to differentiate between Core Solo/Duo and Core 2 Duo processors for 64-bit support.
On a Core 2 Duo, then `sysctl hw.cpu64bit_capable` gives 1, as desired, but on a 32-bit processor, it throws an error, saying:
second level name cpu64bit_capable in hw.cpu64bit_capable is invalid
What's the best way to detect a 64-bit pro...
I've been fighting with getting the MySQL Ruby Gem up and running on Snow Leopard for the past couple of days.
I have tried all different sorts of things to get this working, and currently have MySQL 5.1.37 x64 installed. After fighting to even get the Gem installed I believe that I finally got it installed, but whenever I attempt to ac...
Background: Standard RIT computer engineering student. Took computer science courses (Java, then C++). I spend a lot of time on tech sites, so I constantly hear about scripting languages like Python, Perl, and Ruby. Besides them being scripting languages, I basically don't know anything else about them.
I have a lot of experience in...
I have Ruby code similar to:
ok.rb
hasil = "input operator salah"
puts hasil
exec("sort ok.rb > output.txt") if fork.nil?
It just wrote all code into output.txt. However, I only want hasil result to be written to output.txt. How should I modify the code for such an end result?
...
for Export to CSV, i have overall 2500 records, and while exporting it
takes long time to export all records, so, i have decided to export in
the form of 1st 50 students,and, 2nd 50 students,so on. I have tried
the below code. but it could able to fetch only 1st 50 students.
please, guide me how to solve the problem
def exportcsv
@...
I've been trying to get my head around doing things using my Rails relationships as opposed to pulling out large SQL joins, but I can't wrap my head around this one...
I have 3 models
Hotels
Rooms
Availables
They all have the appropriate has_many and belongs_to relationships.
What I want to do is on the overview page listing th...
I have a method that I've started to use in multiple models for Webscrapping, where is the best place to keep it? Should I put it in the application_controller, application _helper? I'm not sure where a good place is to put it for multiple models to use it?
def self.retryable(options = {}, &block)
opts = { :tries => 1, :on => Ex...
I have a fantasy football league rails app that was working last year and it's time to get it going again before the season starts. I cleared out the database and did a "rake db:migrate" so I could restart the app from scratch. The login page comes up fine but when a user tries to "sign up" using restful_authentication I get the followin...
I'm having some issues with my code. This is probably due to some design fault. I've tried several things. Here are two.
Issue: I have a 1 (lending) - N (contracts) relation. I'd like to call lending.current_contract which would return the last relevant contract.
Optimization is also an issue. I'd like to call :lending, :include => :con...
beside the fact that accessibility standards discourage the use
of a link pointing to the current page, how I am supposed to
refactor the following view code?
#navigation
%ul.tabbed
- if current_page?(new_profile_path)
%li{:class => "current_page_item"}
= link_to t("new_profile"), new_profile_path
- else
%...
I'm writing a plugin that adds a method to controllers and declares it as a helper method. If it were done statically (rather than through the plugin), it would look something like this:
# in RAILS_ROOT/app/controllers/stuffed_animals_controller.rb
class StuffedAnimalsController < ActionController::Base
private
def bear
'Teddy...
I want to clean an HTML page of its tags, using Ruby.
I have the raw HTML, and would like to define a list of tags, e.g. ['span', 'li', 'div'],
and create an array of regular expressions that I could run sequentially, so that I have
clean_text = raw.gsub(first_regex,' ').gsub(second_regex,' ')...
with two regular expressions per tag (...