Cooler
This page is for random comments, discussion, etc.
Questions for the Dec. 17 Panel go here: http://e168f08.plugh.org/cooler/panel-of-rubyrails-professionals-dec-17/ (same password as for downloads)
This page is for random comments, discussion, etc.
Questions for the Dec. 17 Panel go here: http://e168f08.plugh.org/cooler/panel-of-rubyrails-professionals-dec-17/ (same password as for downloads)
Add New Comment
Viewing 162 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Here are some brief notes on getting a Rails job:
0. The course is good for looking for a job, but it would be a component in a whole package involving who you know, what you know, and how you grow as a developer.
1. Who: You really should start networking by going to meetings of the Boston Ruby Group (http://bostonrb.org/). For women, e-mail Amy about her new group for Women and Ruby and Boston.
2. What: I would advise everyone to start downloading and reading code. There are countless awesome Ruby/Rails packages you can find at RubyForge and/or Github. What you want to find are full apps. Then go over the code. Also, you may well find projects that need documentation or light fixes. You would be amazed at how many sophisticated projects have open tickets that are essentially one-line fixes. To learn how to contribute patches and fixes, Google for a screencast on using Github.
3. Growing: You need to think of your developer status as a work in progress. Make a list of things to learn. E.g., if you've never configured a Linux system, learn by doing it. If you've never used source control (e.g., subversion), set it up. If you've never used a bug tracker, set it up. All of these tools can be useful for your personal use.
Do you already have an account? Log in and claim this comment.
Having been laid off mid last week, a new adventure begins. I want to use this time to retool.
The calculus I am trying to solve is how long it will take for me to become employable in RoR. It seems to me, 6 to 18 months.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Hi, I am trying to rake package to submit but for some reason the rakefile isn't getting packaged up. It seems to be the only file that's missing. The weird thing is, it's in the package directory but it's not in the .zip. (I'm using the zip_in_ruby script that came with metricsmine)
Do you already have an account? Log in and claim this comment.
The e168:submit task uses the standard rake package target, so it should be grabbing the Rakefile normally.
I just verified the e168:submit task, but I'm on a Mac.
Just ZIP up your project with any tool -- or, if you like, use the e168:submit task and zip up the Rakefile separately.
Do you already have an account? Log in and claim this comment.
I was making the code clean now few things don't work and I do not know why.
My logout does not logout anymore -
Console shows that email is genereated and sent, but i never get in my inbox.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Thanks
Do you already have an account? Log in and claim this comment.
I just sent an e-mail out on that topic. I covered some of the expectations here: http://e168f08.plugh.org/assignments/final-proj...
As far as length, "what it should look like," etc.: The key is to think about the audience. The audience is a developer like yourself who must understand (1) What the app is supposed to do; and (2) how it is implemented. If you are like me, this is a high standard -- I personally need very clear and complete documentation to understand someone else's work.
John
Do you already have an account? Log in and claim this comment.
I'm exposing an atom feed for a user at the url: http://localhost:3000/posts/feed/username.atom
In my posts controller:
def feed
@user = User.find_by_login(params[:id])
@posts = @user.posts.find(:all, :order => :created_at).reverse
respond_to do |format|
format.html
format.atom
end
end
Now in the html I want to put in an link tag using <%= auto_discovery_link_tag :atom, {:controller=>:posts, :action=>:feed, :id=>@user.login }, {} %>
But that gives me
http://localhost:3000/posts/feed/username
instead of
http://localhost:3000/posts/feed/username.atom
Is there any way I can get the suffix in there?
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Can anyone suggest a good summary of the differences between all the different ajax remote tags and when to use which?
Thanks.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
My experience with Nokogiri is that it's not quite there yet.
Do you already have an account? Log in and claim this comment.
require 'rubygems'
require 'open-uri'
require 'nokogiri'
module AsanasHelper
def self.feed
doc = Nokogiri::HTML(open('http://www.yogabasics.com/asana/postures/*.html')) #this doesn't work.
poses = doc.search('/html/body/div/div/div/div[5]/div[div/div/span/@class="pathway"]')
postures = []
poses.each do |pose|
english = pose.search('span[@class="pathway"].first').text
. . . .
postures << {:message => "searching yoga plexus", :english => english, :sanskrit => sanskrit, :basic_instruction => basic_instruction} #:difficulty => difficulty, , :benefits => benefits, :contraindications => contraindications
end
return postures
end
end
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
thanks
Do you already have an account? Log in and claim this comment.
In your case: Use hpricot or nokogiri.
Do you already have an account? Log in and claim this comment.
filenames = Dir.glob("*.html")
filenames.each do |filename|
doc = Nokogiri::HTML(open(filename))
end
see http://www.ruby-doc.org/core/classes/Dir.html#M...
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
save_these_words.each { |each| each.save }
I read Time.now before that statement and again aftewards, and it confirms that this is the major bottleneck. (The value is 6.8 seconds)
In the ouput of script/server there are a bunch of these lines:
UPDATE "words" SET "current_index" = 816, "current_position" = 19239 WHERE "id" = 2166
A bunch print out at once, there's a pause, then another bunch, etc, for around 5 seconds, for roughly a thousand rows from id=1300 to id=2300. There is a lot of hard disk activity too.
Do you already have an account? Log in and claim this comment.
How much RAM is on your computer?
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
The total time to update 3000 rows, row by row, in Sqlite3, is: 60 seconds.
I also tried it on MySQL: 47 seconds.
You are updating each row separately. 3000 / 60 is 50, so you're updating 50 rows per second.
I don't know enough about your application to know what to recommend. What does your application do? Does this need to happen very frequently? Or can it happen once a night or once per hour? If the answer is "Yes," then you should run this update code periodically with a scheduled task or cron job.
Does the data need to be access immediately after it is updated? If the answer is "no," you could update the data asynchronously with Workling (see http://github.com/purzelrakete/workling/tree/ma...)
Does the data need to be accessed "row-wise" or do you tend to want to grab all 3,000 rows each time? If the answer is the latter, then the data should not be kept in rows. Let us say that it is a Hash, and you want to grab it once, update the 3,000 items, and save it back at once. What you would want to look at is the ActiveRecord "serialize" feature which allows for saving a big object as one column value. If you want to know more about this, let me know.
If it is the former -- the data has to be accessed row-wise, and you also need to update 3,000 rows at a time -- we should talk.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Quick comment on setting up the external site. My Ubuntu server on slice did not come with 'make'. I used "sudo apt-get install build-essential" to install the gnu compiler, after which all worked well.
I may have missed a step in the tutorial. Perhaps this will help a classmate.
Take care,
Mike
Do you already have an account? Log in and claim this comment.
Googling now.
Mike
Do you already have an account? Log in and claim this comment.
Mike
Do you already have an account? Log in and claim this comment.
My Sequence form is the most complicated. In a single region I need to have:
one form that just wants to collect preferences (pose type and pose subtype) so the app can narrow what's listed in the next section. If the user selects either type or subtype the next section will list only the poses that are children of that type/subtype. If the user selects both type & subtype the list will include only poses in both sets (overlapping). I want to do something like <% form_tag {:action =>"accept_asana_categories_and_return_asanas", :id => @asana_type } do %>.. but instead of choosing just @asana_type I want to return either/both asana_type and asana_subtype as parameters to "accept_asana_categories_and_return_asanas".
Any ideas as to how to accomplish that?
The next form needs to list a collection of asanas based on the first form's returned parameters, types/subtypes; each pose is a link that will create a new row in the join table, asanas_sequences. Ultimately when Ajax comes in (I haven't even been able to think about Ajax yet!) the list of poses will update automatically.
Do you already have an account? Log in and claim this comment.
Then it might be a lot simpler.
Do you already have an account? Log in and claim this comment.
If we have the following model:
class User < ActiveRecord::Base
belongs_to :clinic
we can say things like:
validates_presence_of :clinic
but we can't say:
validates_uniqueness_of :login, :scope => :clinic
instead we have to say
validates_uniqueness_of :login, :scope => :clinic_id
since the "belongs_to :clinic" in the migration for the user model creates a column called "clinic_id" not "clinic".
This seemed very counter-intuitive, and took me a number of hours to debug so I thought I would post for others.
Do you already have an account? Log in and claim this comment.
I.e., 'john' for clinic #1, 'john' for clinic #2.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
map.resources :sequences
map.resources :sequences, :member => { :get_postures => :get }
map.resources :sequences, :has_many=>:user_observations
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
How can I add a standalone class to RoR ? I have some source code which I wrote, it works perfectly as a script, there is a class called "IMDB" which, you guessed it, scrapes IMDB for content. I run it from the command line or with a wrapper, but want to get it into my rails site. Where do the files go, and how do you "require" them in the right place?
(I'm a C++ developer and can't believe that ruby would have an obvious solution to this too)
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Sequence: has_many :somethings
Sequence: has_many :asanas, :through :somethings
That kind of thing.
Do you already have an account? Log in and claim this comment.
AsanasSequences is the join table. I implemented acts_as_list so that users could rearrange the order of postures in their sequences. The actual name of the association I want to validate in Sequence.rb is "postures", and each of these is an instance of AsanasSequences that relates to one of the asanas.
To access the properties of an asana in a Sequence named sequence1 you need to use sequence1.posture.asana.
Here is the class def for Sequence:
class Sequence < ActiveRecord::Base
belongs_to :user
has_many :postures, :class_name => "AsanasSequences", :order => :position
has_many :asanas, :through => :asanas_sequences
end
thanks!
catherine
Do you already have an account? Log in and claim this comment.
class Sequence . . .
has_many :postures, :class_name => 'AsanasSequences', :order => :position
has_many :asanas, :through :postures
The value of :through is the name of the ASSOCIATION through which you have many. So here it should be :postures. Maybe it works with :asanas_sequences.
Now that I see this model: Are you sure you want to disallow a Sequence with no asanas? Why?
Suppose in my UI I want to create a sequence named "foobar" and then add a bunch of postures -- Right after I create the sequence there would be no associated postures. So it seems to me that it would not be wrong ot allow the collection to be empty.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
E.g., if a Book belongs_to :user , you would check user_id to be non-null. You can also set that in the migration so AR will enforce it there.
Do you already have an account? Log in and claim this comment.
I'm working on some test capabilities for the final project. I want to be able to run a server which will inject messages using HTTP to my WEBrick web service.
I've created a script which will do this. I can make it run as long as I do not attempt to access any User Defined Classes, for example Classes in my app/models directory.
I've tried to include the environment by using:
require File.dirname(__FILE__) + '/../config/boot'
which is apparently how the script/console and other scripts pull in the Environment variables. The script does not recognize my model classes. If I require them in my script explicitly, I can see them, but if they refer to additional classes (maintained in the lib library), Ruby complains about not being able to find them.
Is there any way to make this work? Please let me know if you need me to provide more information.
Mike
Do you already have an account? Log in and claim this comment.
http://localhost:3000/users/1
and the like?
Do you already have an account? Log in and claim this comment.
I have an XML file I read in to pull some specifics about the User and the site to be tested.
I set up a log file to ouput status.
I've created 500 or so components in the DB I need to update through HTTP POSTS.
I've been using: res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } to do so, from within a Windows Service I built.
In the Windows Service, I don't need access to the local classes... I'm just pulling a small amount of information from the XML file and from the local PC.
In the case of the test, I wanted to pull the specific endpoint information from the System Under Test. I can get at the classes to pull information, but one of the ones I need to access implements "acts_as_mappable". This is a class located within the lib/geo_kit directory. Unfortunately, I can't seem to be able to get the script to see this file.
My next step is to comment out the acts_as_mappable, in my locations model, to see if I can make it work...
Here's the script so far:
require File.dirname(__FILE__) + '/../config/boot'
require 'rubygems'
require 'activerecord'
require 'xmlrpc/client'
require 'win32/daemon'
require 'net/http'
require 'uri'
require "rexml/document"
require 'user'
mappable_path = '../lib/geo_kit/acts_as_mappable'
require 'location'
require File.dirname(mappable_path)
LOG_FILE = File.dirname(__FILE__) + '/test.log'
#here we want to read in the xml config file
@doc = REXML::Document.new File.new("./config/test_config.xml")
#open the log file
File.open(LOG_FILE, 'a+'){ |f|
f.puts @doc
}
#establish the xml doc root
root = @doc.root
#grab the user name & pwd for the test
@user_name = root.elements[1].elements["user_name"].text
@pwd = root.elements[1].elements["pwd"].text
@remote_server = root.elements[4].elements["remote_server"].text
# Initialize ActiveRecord
config = YAML.load_file('./config/database.yml')
#grab the development configuration
spec = HashWithIndifferentAccess.new(config['development'])
# Uncomment the next two lines if you want to see the SQL
# ActiveRecord::Base.logger = Logger.new $stderr
# ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(spec)
msg = 'Testing script started at: ' + Time.now.to_s
File.open(LOG_FILE, 'a+'){ |f|
f.puts msg
}
url = URI.parse(@remote_server + '/svc/post_kw_reading/')
req = Net::HTTP::Post.new(url.path)
req.basic_auth @user_name, @pwd
#find the locations for the user from the config file
locations = User.find_by_login(@user_name).locations
#create an array to hold devices
devices = Array.new
#add the devices for the user to the array
locations.each {|l|devices.push location.devices}
#start the while loop which will send usage data to the web server
#appearing as actual clients
while true
for device in devices
#make up some kw and voltage readings
kw = rand(10)
volts = 119.5 + rand
req.set_form_data({:kw => kw, :volts=>Vrms, :guid=>device.guid,:cost=>'0.22'} )
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
File.open(LOG_FILE, 'a+'){ |f| f.puts res }
else
File.open(LOG_FILE, 'a+'){ |f| f.puts 'Error in posting' }
end
sleep 60
end
end
Do you already have an account? Log in and claim this comment.
class Exerciser
def self.run
# YOUR SCRIPT HERE
end
end
Now from the root you can do
script/runner "Exerciser.run"
(Check script/runner in AWDR)
Do you already have an account? Log in and claim this comment.
acts_as_mappable and uuidtools. Neither of these are required for my current testing. They are used for adding devices and locations.
So.... will use your idea right now... and let you know how it goes.
Thanks!
Mike
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Works like a champ without the requires!
Thanks!!!
Mike
Do you already have an account? Log in and claim this comment.
But this all looks mostly like "AJ" without the "AX". The "standard" way of doing Ajax (or at least the style that I'm used to) involves the server sending DATA (usually structured in some form, hence "And XML") to the browser, to be processed by client-side JavaScript. AWDR mentions the possibility of this in passing, but shows no examples. Can we see some examples of Asynchronous JavaScript AND XML (or AND JSON)? How does the code in the view deal with parsing and/or evaluating JSON or XML returned by the server? For the Ajax-worthy bits of my final project, I can't easily see any way that the view would know which elements of the page to update, without embedding code that more properly belongs in the controller.
Do you already have an account? Log in and claim this comment.
Also, about the target id:
Understand that you are clicking on something (triggering a browser event). So, you write view handler code to catch that event, trigger a controller call, and then take the result and shoot it into an element (or its innerhtml) with that id. So the actually move from event to target is all handled in the view, probably where it should be. Indeed, if the controller picked the id, that would strike me as problematic.
You can send JSON (easily) but I believe that if you want to respond to it in your JavaScript, you are going to have to write that JavaScript manually. Let me check with someone here at the office.
Do you already have an account? Log in and claim this comment.
I see that when using a partial, the distinction between the View and the Controller is being maintained, but at one stage of your first lecture example, the controller is just rendering text to be inserted into the innerHTML of a DOM element, and it seems that it could be very easy and tempting to start rendering actual HTML markup in the controller (or, as in the case of echo_observer1, rendering as text any HTML markup that might be in the user input; a quick browse of the the Rails API and AWDR doesn't show me the usable-by-controllers version of ERB::util#html_escape).
Regarding the element id. In some cases, it's not always trivial to determine which DOM element should be updated after an Ajax call completes. The element could be different for success or failure, or the result could be dependent on information in a form on the page, which needs to be processed to determine which element (if any) to update. My real-world example here is what I'm thinking about for my FP, where there will be a datetime_select which should be processed to determine which <td> in a calendrical table should be modified. I don't think a view should be doing this kind of processing, but the controller can send back structured information which enables JavaScript embedded in the view to compute the element id.
Other examples of when one would want to process the reply, instead of simply replacing the innerHTML of an element, would perhaps be when the contents are large and unchanged, and one just wants to modify attributes of that element, e.g. style.
Do you already have an account? Log in and claim this comment.
Duh. That's because it's part of core (non-Rails) Ruby. Improved code for echo_controller:
def echo_observer1
render :text => CGI.escapeHTML(params[:echo_observer_text])
end
and, correspondingly, in the views, (echo1.html.erb and the partial view _echo_text.html.erb), there should be an 'h':
<%=h echo_text %>
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
I agree that using a partial is better, because it preserves the VC distinction. I was commenting on the intermediate stage in the lecture ajax-refactorying example, where the echo_observer1 action renders text directly. This is a good argument against rendering text.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
I think the best practices are:
-- Single update of a block of HTML: Use a partial
-- Single data item, numeric or short String: Possibly render text; probably better to just go with a partial
-- Update multiple parts of the page: Use RJS
-- Supply JSON or XML data to Prototype: Render JSON or XML (for XML, possbility use builder)
-- "Catch" JSON or XML . . . You're on your own. If you use Prototype, at least the methods are based on Ruby iterators.
The gap is that Rails is good at marshallng data back in XML or JSON, but doesn't give you much in terms of "catching" that data in the view and doing something with it.
The Rails answer for "how can I update multiple parts of the page" is: Use RJS.
Incidentally, what is your use case where you want to send data back to the client?
Do you already have an account? Log in and claim this comment.
This still feels gross to me, as if it's violating not only the View/Controller distinction, but also the Client/Server distinction. I realize this is probably unreasonable, but the idea of shipping executable code to the client just feels spooky and icky.
>Incidentally, what is your use case where you want to send data back to the client?
Adding an event to a calendar, with a simple "add an event" form on the same page as the table holding the calendar. I don't want to re-render the whole calendar, just the one (at most) <td> that represents the date of the event (if that date is within the currently-displayed date range)
Do you already have an account? Log in and claim this comment.
Also, since the KIND of executable code exercised on the client is primarily about updating the view, it's arguably still within the responsibility of the view.
If client-side JavaScript is shipped data (via JSON) and updates the view asynchronously, if you're an MVC purist then you have to be very careful to separate your concerns there as well. So I think really that RJS constrains you in a nice way.
For the calendar:
-- If the calendar is displayed in a table, you might as well re-render the entire table, because dynamic table cell updating is uneven across browsers, even with Prototype. I think there's a callout somewhere in AWDR that discusses this a bit.
-- If the calendar is a list of dates and events: If you display the calendar as a list (ul and li tags), then you can update ":before" or ":after" something, and you should be able to squeeze a new item in at the start or end of the list. Having it update in place (i.e., a new event in between two other events) would require you to have a unique id for each list item.
In any case, get it working without Ajax first.
Side issue for anyone who is reading: Incidentally, last night after the panel, Amy told me that I overstressed backwards compatibility / graceful degradation. If you are using an Ajax-only component -- such as Google Maps -- then you certainly don't have to render all of the information in the map when JavaScript is turned off.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
This gets a bit in-depth, but it is a description of how Facebook is making use of, and modifying, memcached and the considerations in scaling Web 2.0 applications. There seem to be a lot of people out there using ROR to build applications for Facebook.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
If say ModelB has a field that belongs_to :ModelA, must ModelA has a matching has_xxx field ?
There is a "has_one" and a "has_many". My situation is has_zero_or_one, and I am not
clear whether has_one means EXACTLY one, though has_many seems to cover the case of 0 to many.
To repeat myself, just to be clear, say ModelA has fieldA, fieldB, fieldC. fieldB references modelB.
There are modelB that does not reference any modelA. What relationship should this be ?
Thanks
Do you already have an account? Log in and claim this comment.
ModelB belongs_to :model_a
In Rails, this means that the table underlying ModelB (model_bs) should have a foreign key called model_a_id. That is, a row in model_bs "refers" to a row in the model_as table. In other words, the column model_a_id is a foreign key. ModelB is a "child" of the "parent" ModelA.
The table model_as does not have a foreign key.
When we define ModelA, we can say in our association that it:
has_one :model_b
OR
has_many :model_bs
In the first case, there should be 0 or 1 rows in model_b. In the second case, 0 or more.
The reason you are having trouble with this is in your last paragraph. You write: "Say ModelA has fieldA, fieldB, fieldC. fieldB references ModelB." But that's not how it works. The foreign key is in the CHILD. The parent model DOES NOT HAVE A FIELD that refers to the child. The only way we can "trace" the relationship between ModelA and ModelB is through the *association* -- the *association* (namely, has_one :model_b or has_many :model_bs) is not about FIELDS. It's about a method that allows you to collect up all of the model_bs.
Finally, something to think about is whether ModelB (whose underlying table model_bs has the foreign key model_a_id) is allowed to have a null for the value of the foreign key. This is something you would have to decide for your own application.
I think what I've just written is correct though with names like "ModelA" and "ModelB" I might have gotten something backwards. This is why in the examples I've tried to show somewhat plausible model names like "Book" and "IndexEntry" so that there are some semantics to provide cues as to what is the parent and what is the child.
Do you already have an account? Log in and claim this comment.
So, now, I know that
- "has_one" includes the case of ZERO as well,
- NULL is allowed for the value of the foreign key
Thanks
Do you already have an account? Log in and claim this comment.
Let's say that model_a is for people, and model_b is for their company: And we say that ModelA has_one :model_b (so a person has 0 or 1 companies - this is not necessarily the way the real world works, but it's how we're going to do it).
Example:
Rows in model_a (columns are: id, name):
1 John
2 Bill Gates
3 Steve Jobs
Rows in model_b (columns are: id, model_a_id, company_name):
1 1 digital_advisor.com
2 3 apple
3 2 microsoft
4 null ibm
5 null dell
6 3 apple
7 1 beatthat.com
NOTICE the following facts:
(1) Even though our association says ModelA :has_one :model_b, it happens that there are TWO rows in model_b where the foreign key is "1" (for John). That is because having just one is not enforced at the database level with more work. I believe Rails will try to enforce the 0 or 1, but if someone forced that row into your table manually, Rails would just bring back one row from model_b when you follow the association from ModelA.
(2) The rows in model_b with nulls for the foreign key value are essentially "orphans." They don't know to whom they belong.
Both of these situations (1) and (2) are problematic. If you want to control whether a null is allows in the foreign key in model_b, look at the ":null" option for columns in the documentation-- in AWDR on p. 277. :null seems not to be in the index.
Do you already have an account? Log in and claim this comment.
What I try to model is slightly different.
Let's say we want to buy something (a house, perhaps).
You make an "offer".
If all goes well, this "offer" results in a "transaction".
So in my case, the "transaction"(modelB) if one materializes, belongs to an "offer" (modelA)
An "offer" on the other hand, may or may not result in ONE transaction. If no one buys the house, the "offer" will not have a corresponding.
The "transaction" will never have null value for its foreign key because it is result of an "offer" made.
So, I think that I won't be running into the problematic situation (2) for this case.
Thanks
Do you already have an account? Log in and claim this comment.
I'm thinking about the final project, and as one of the elements, I'm interested in maintaining minute by minute usage data associated with internet enabled equipment. But I'd like to roll the data up into hours, days, weeks, and years, so that I will not have to maintain hundreds of thousands of rows for each user for each year.
Is there a best practices way of doing this? I've been thinking about writing it myself using after_save callbacks on a Usage table. But, it's not all together trivial due, amongst other things, to some recursion issues I foresee (I foresee, I foresee, I foresee :-). I'd be very happy to find out someone has already figured this out and has written a gem or plugin...
Thanks,
Mike
Do you already have an account? Log in and claim this comment.
The original collection could be into a flat file or into a database table (you would truncate or archive the original data after you summarize it). You would surely want to archive it.
The standard way to manage rollups is with a table such as the one used in MetricsMine. You are free to use it. Note that that table doesn't have indices. You would want to keep your data in a database such as Postgresql or MySQL which does allow for indexes.
In any case, the big question for you will be what you want to do with the immediately-collected data before it gets summarized. Will users want to see their data trickle in within the hour?
Do you already have an account? Log in and claim this comment.
The difficulty is the missing data... machines go down and so do internet connections. Therefore, the data will have missing elements, which in some cases will span hours, days or weeks. So, I need to be able to handle missing observations as well.
I'll take another look at the rollups in MetricsMine. I may be able to use some or all of it for this purpose.
Thanks,
Mike
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Thanks,
Mike
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
A very quick web search reveals this article
http://myersds.com/notebook/2006/05/11/how_to_g...
which seems very clear, which is just using generic Builder to put together the XML for an RSS document, which raises the next question, whether AtomFeedBuilder is providing any real added value, compared to just building an Atom feed out of raw XML
Do you already have an account? Log in and claim this comment.
This is a biased account, but will give you some of the flavor for why you might go for Atom:
http://www.intertwingly.net/wiki/pie/Rss20AndAt...
This is a big deal: http://www.intertwingly.net/wiki/pie/Rss20AndAt...
Re: building an Atom feed out of raw XML: If you use the atom_feed helper, then if common usage moves to a different version of Atom, you'll have built your feed using a higher level API, which might get updated -- and then you don't have to dig around in your own home-build XML.
There is nothing wrong with providing both kinds of feeds. "One resource, many representations." If you include two "auto discovery" links, must feed consumers will give you an option to select (atom vs rss 2.0, etc.).
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
If you want to support RSS, which one? Should you expose 0.9 AND 1.0 AND 2.0? Do we need to support ALL of those? There is doubtless a plugin that will do all of that for you; I would bet that DHH would say that Rails, being "opinionated software" advocates Atom . . .
Do you already have an account? Log in and claim this comment.
datetime_select(object_name, method, options = {}, html_options = {})
but in practice we call it as something like
form.datetime_select :observed_at
with the implicit @observation (or :observation) as the object, and :observed_at as the method on that object.
Two questions:
1) How does this work, from a language viewpoint? Do these methods examine the types of their arguments, figure out that the first argument is the name or symbol of a method rather than an instance variable, and adjust the argument list appropriately?
2) More importantly, other than by reading AWDR and intuiting the methods' behavior from the code examples, how would we be able to figure out that some arguments (not the trailing arguments, and not those shown with default values in the method signature via an '=' character) are optional?
Do you already have an account? Log in and claim this comment.
2) The on-line documentation is bad, in my humble opinion, because it underplays what the "form builder" (the variable form_for yields). The docs (http://api.rubyonrails.org/classes/ActionView/H...) say:
The generic way to call form_for yields a form builder around a model . . . (and they quote an example) . . .
There, the first argument is a symbol or string with the name of the object the form is about, and also the name of the instance variable the object is stored in.
[KEY SENTENCE -->] The form builder acts as a regular form helper that somehow carries the model. Thus, the idea is that
<%= f.text_field :first_name %>
gets expanded to
<%= text_field :person, :first_name %>
-----
And that is the whole enchilada. You can use any of the form helpers via that "f" or "form" or whatever variable you have assigned to the one yielded to you by form_for.
The RDoc generator that makes the HTML pages should cross-reference what is happening here so that whenever you're looking at "datetime_select" there is some indicator of how you would use it from form_for; and the idea that the variable form_for yields magically sprouts these methods that delegate can't be overplayed enough.