DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

Student1's picture

Unregistered

Feeds

aliases

  • Student1
  • student1

Student1

6 months ago

in Cooler on e168f08
Thanks.

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

6 months ago

in Protected: Panel of Ruby/Rails Professionals, Dec. 17 on e168f08
But we won't know when that panel would be unless somehow you email us :-)
1 reply
xertroyt's picture
xertroyt I will e-mail anyone who tells me they're interested.

Or you can take Jim's course: http://extension.harvard.edu/2008-09/courses/cs...

6 months ago

in Cooler on e168f08
Ah, I got the ModelB and ModelA mixed up in my 2nd paragraph, but what you described in your first 10 lines is what I was thinking.

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
1 reply
xertroyt's picture
xertroyt Yes, but make sure that you understand: The fact that the foreign key can be null has nothing to do with has_one vs. has_many.

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.

6 months ago

in Screencasts on e168f08
Yes I would like to see Rails application getting deployed into JavaEE

Are there other reasons for JRuby, such as performance reason ?

Thanks
1 reply
xertroyt's picture
xertroyt JRuby performs as well or better that the "sandard" Ruby interpreter.

The big advantage of JRuby for web apps is that the JavaEE container can have multiple "Rails" applications running in the same container.

Until recently, in the conventional Rails world, one would literally run multiple copies of Rails on the same physical server.

This blog posting goes over some of the options.

http://weblogs.java.net/blog/arungupta/archive/...

6 months ago

in Cooler on e168f08
I have a question on 1-to-xxx relation that wasn't clear to me.

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
1 reply
xertroyt's picture
xertroyt Let me say it a bit differently. Let us start with:

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.

7 months ago

in Screencasts on e168f08
Could you show us JRuby ?

When the class is over, could we still access these screen casts ?

Thanks
1 reply
xertroyt's picture
xertroyt I will leave the screencasts up unless my bandwidth bill increases!

JRuby is a good idea. I'll think about it. I think what everyone would like to see is a Rails application getting deployed into a JavaEE container.

7 months ago

in Screencast - RestfulAuthentication - 1 on e168f08
Though this worked for me, I am not sure that I could make this work, without following the instructions step by step. There's a lot of configuration, installation, version-matching going on that I am not familiar with at all. There's still a lot of magic. I am wondering if the OPEN ID, which was part of the final project is as complicated.
I am not sure what the relationship between OPEN ID and the restful authentication.
If it is that complicated, I probably would not choose this feature in the final project.


By the way, since I can reuse the same email address when testing, is it safe just to go into the database and
change the email address of existing user, and hence, when I retry creating a different user, I can reuse my email address.
1 reply
xertroyt's picture
xertroyt A few points:

1. restful_auth gets you more than just the ability to login: It provides for securing your REST data so that unathorized users can't use your service. Open id alone would not get you that.

2. All open id is about is having your credentials clearing happen on another server. By this means, you enter an open id into a site that supports it, and then the check for your credentials jumps to your open id provider. If you check out, then it jumps back to your app. So, in a lot of ways, open id is a whole different thing. Since maybe users don't have open id's, it is a terrible idea to support only open id.

3. You can blend in open id to restful_authentication. I believe there is a screen on this at railscasts.com -- i hcw no idea if the procedure outlined there would work with what I've described in my screencast.

4. There *is* a lot of magic implementing restful_auth. That is why I provide the screencast. It's hard. On the other hand, authentication is also hard (actually really hard to get right -- cookie handling is just the tip of the iceberg).

5. I actually think the restful_authentication plugin is pretty awful. Please don't quite me. There are things coming along that will be better.

7 months ago

in Assignment 3, Milestone III on e168f08
But I did this { :action => :create_observation, :id => @observation_set.id }

So, some comes in the view as an @observaion_set
The view does what it needs to do,
but, with :id => @observation_set.id, the params[id] is now set to what comes into this view as @obervsationse

So, in summary,
a <value> comes into the view as an instance variable
The value is placed into :id => <value> and send to the controller.
The controller then reads the <value> from params[:id]

Is this not okay ?

Thanks,
1 reply
xertroyt's picture
xertroyt When you create an OBSERVATION, should its (the observation's) ID (the unique id that identifies a particular observation) be set to the id of its observation set?

No. The observation_set_id on the observation should be set to the observation_set.id. There are two id's in play, one for an observation, the other for an observation set.

When you display a form to create an observation, do you know the id that the database will give a new observation when the form is displayed? No, you don't. The id should not be specified at all for the :create action, because when the create action takes over, it will get the new id from the database.

Would you e-mail me privately? john at 7fff dot com

7 months ago

in Assignment 3, Milestone III on e168f08
I was trying to delete all the metrics I created as an admin on the reference implementation.
It delete multiples rows for each delete key I hit.
I hope that you can reproduce this. Perhaps my problem with ObservationKind delete is related or similar.
1 reply
xertroyt's picture
xertroyt I don't understand what you're saying, because you're not using the language of the application.

If you are deleting observations (metrics), you would use the checkbox and then click "delete checked." There is only one button here, so I don't know what you mean by "each delete key I hit."

If you are deleting observation kinds -- "kinds of metrics" in the UI -- you would be clicking the delete link.

Note that when an observation kind is deleted, then the display of the KIND at the top of the "show" page for the observation set can no longer display the kind. So it is blank. There is an instruction regarding this in the static page for the "show" template.

7 months ago

in Assignment 3, Milestone III on e168f08
Thanks....

7 months ago

in Assignment 3, Milestone III on e168f08
I logged in as Jenny
Also, "the information" is the observation_set id.
I thought we're supposed to save off the last used observation_set id somewhere, so that when the user log on again, he gets send to the page whereby he can add a new observation for the observation set he last used.



Now as an admin
I also noticed that in the reference implementation, the delete also seem to have rows (observationKinds) automatically disappearing.
Also, when I hit destroy for some of the ObservationKind, I to an error page.
1 reply
xertroyt's picture
xertroyt That is correct: When you display a particular observation set, save the current observation_set_id to user.current_observation_set_id.

I cannot reproduce the "automatic" disappearance of observation kinds, or any error page. If you delete all of the observation kinds (PLEASE DON'T!) you will find that you can't create a new observation set (I think). This was discussed earlier, and we said: "An admin would never delete all of the observation kinds, so we will consider this a feature, not a bug."

I have just reset the database. If you can identify a set of seps that will produce this behavior, from login to the error, e-mail the steps to me.

7 months ago

in Assignment 3, Milestone III on e168f08
This doesn't work. I am using FF 3.0
It takes me to the dashboard.

BTW, why do you need o save the information in the database as well as in the cookie ?
I thought that if you save it in the database, then once you look on, you will get the observation set information from the database.
If you save it in the cookie, then you get it from the cookie. Why do we need both ?

Thanks
1 reply
xertroyt's picture
xertroyt What is the username that you are using with http://metricsmine.plugh.org that doesn't work in FF 3.0?

When you say: "why do you need o save the information in the database as well as in the cookie ?", what do you mean by "the information"?

7 months ago

in Assignment 3, Milestone III on e168f08
I spent sometime with this datetime_select...I can't get the seconds. I have month/day/year/hour/mintutes (as the documentation describes). There is no seconds.

I also noticed that it only works if I initialized the Observation by new (params[:observation]). If I try :
@observation.observed_= params[:observation][:observed_at]
the date is not set right.


Now, I am stuck with no second. I tried select_second, but that isn't the method I want.

CCC also doesn't have "seconds".
Why don't we get the second field. It fields so "normal" to have the "seconds" field.
It is quite frustrating.
1 reply
xertroyt's picture
xertroyt Sadly, I'm afraid, this is one of those areas where the view helper docs are not as comprehensive as they should be.

See what happens if you say:

<%= form.datetime_select :observed_at, { :include_seconds => true } %>

This is by analogy to

http://api.rubyonrails.org/classes/ActionView/H...

where there is this comment:

# Creates a time select tag with a seconds field that, when POSTed, will be stored in the entry variables in
# the submission_time attribute.
time_select("entry", "submission_time", :include_seconds => true)

7 months ago

in Assignment 3, Milestone III on e168f08
yes, I think so.

7 months ago

in Assignment 3, Milestone III on e168f08
I think what happens is that I get to the create observation page from the page that list observation set.
When I click on one of the observation sets on the list (the "RAW"), this brings me to the observation_set controller,
with an ID parameter for the set. From this, I can set an instance variable, before going to a view that allows me to add
observation for that set.
Hence, I have the obseravation_set_id.
(It seems to be working ????)

Suppose you just can arbitarily jump to a page that add observation, without going through the observation_set page, then, you wouldn't have the observation_set_id.

Am I doing something not right ? It seems to be working ???
1 reply
xertroyt's picture
xertroyt You must implement it in the same fashion as the reference implementation. Do not introduce extra controller actions and/or views.

So, this means:

-- The controller/action that sets up the form must be: ObservationSetsController#show
-- The form displayed by views/observation_sets/show.html.erb must be "for" the :observation model
-- That form must post back to the :action => :create_observation (on ObservationSetsController)

Are you doing those things?

7 months ago

in Assignment 3, Milestone III on e168f08
So does that mean that we don't have to necessarily do the hidden variable (b), since I was using the instance variable method (a)

Thanks
1 reply
xertroyt's picture
xertroyt I don't see how that would work.

Think about it this way:

-- You set an instance variable.
-- A form is displayed.
-- The user clicks "submit" or "add observaiton" (whatever's on the button).
-- Now a new controller receives the request (i.e., the "post" of the form)

How does this new controller know what observation_set_id you want?

You have to get that observation_set_id into the params hash.

And how do you do that? Include the observation_set_id in a hidden field.

7 months ago

in Assignment 3, Milestone III on e168f08
In the reference implementation, I don't see me being directed to a page to "add observation".
We are supposed to save the observation set id into the user table. We save off the last observation set the user chooses.
However, I don't see how we use this information.

When I log on, I get to the dashboard, which allows me to:
- logout
- Get a list of metrics (i.e. observation sets)
- Create a new observation set
- Compare

So, I don't see how and where we direct a user to a page with the most recently used observation set.

The assignment reads:
"There are some small changes between this version and the prior version: 20081111021247_add_current_observation_set_id_to_user.rb adds a column to user “current_observation_set_id” - whenever you view an observation set, the id is saved here so that when you log in from a cookie, you can be redirected to that set: This makes it especially easy to enter a new observation for whatever set you were last looking at. "

So, when I log on, assuming that there's a cookie, do we not go to the dashboard, and instead go straight to the page where we can add new observation s?

Thanks
1 reply
xertroyt's picture
xertroyt To see how you get directed to the page on which you would add an observation:

(1) Log in.
(2) close your browser without logging out.
(3) Go back to the application. See where you end up?

If this doesn't work for you, let us know.

Reason for this behavior: There is ONE activity that the user wants to do every day: Post data. If you have ever tracked your weight, you will do anything to avoid this behavior. Therefore, the application makes it as easy as possible.

7 months ago

in Assignment 3, Milestone III on e168f08
I still don't see why I would need one in creating an observation.
The hidden field is to store the observation_set_id. However, I put that in an instance variable. THe way I get to the observation creation is by clicking from an observation set list, so I don't see where I would need one.
1 reply
Keith The instance variable doesn't persist to the next request. When you click on 'Add', you won't have access to @observation_set_id any longer.

7 months ago

in Assignment 3, Milestone III on e168f08
In the reference implemenation, if you click the "Delete Checked" button,
and if you do not check any box (for observations), then, there will be a page telling me that something went wrong.
1 reply
Keith Looks like that is a bug.

7 months ago

in Assignment 3, Milestone III on e168f08
Regarding the hidden field, I am a bit confused:
(1) The form itself does not have anywhere one could change the observation_set_id to begin with.
So, I don't know how the user can change this.
(2) So far, I have been embedding them in a instance variable. Is that okay ?
The way I get to adding an observation is by clicking on an observation set, in the list of observation sets.
So, as a result, I get into the controller knowing the observation_set_id.
At that point, I can set an instance variable which passes to the view.
The view will go back to the controller by setting a parameter using that above instance variable.

as in:
<% form_for :observation_set, :url => { :action => :create_observation, :id => @observation_set.id }

Does this not work ? Or should we set the instance variable instead.



I have a different questions. The time in creating observation - there are broken up into 6 fields. Each of the time related field does not
by itself correspond to an attribute for the observation. So, I simply create a different hash altogether.
Does that sound reasonable ? I use "select" to generate the options for hour/min/sec/year/day. But I don't see a month_selection helper.
I wound up using html. Is this expected ? This seems to work, but I have a feeling that the month_selection is often used, so there may be some method I am missing. Am I doing it right ?
3 replies
xertroyt's picture
xertroyt I see that there are some answers already to some of these questions, but here are some brief confirmations of what is below:

-- When an observation is added, it must be added TO an observation set. Therefore, when the form that lets you add an observation posts back, there must be some indication of the observation set id to which that observation should be added. Therefore: (a) you may pass the observation_set_id to the form in an instance variable; (b) use a hidden field to capture that id so that it is sent back when the form is posted; (c) in the action to which the form posts, obtain the observation_set_id from the params hash.

-- For time forms in forms: Take a look at the ChildCare Co-Op application. The helper is: datetime_select - it has many options.
Morris For selecting a time in a form, there are helpers for this in the ActionView::Helpers::DateHelper class. http://api.rubyonrails.com/classes/ActionView/H...
I thought I had seen an example of this somewhere in John's sample code, but I can't find it now. I'm fairly sure AWDR gives some examples.

You could pass the observation set id as a parameter in the URL for the form, but my personal interpretation of the requirement not to change the HTML is that we're supposed to use the hidden field in the form, which will make all of the information stay in the POST parameters. There are helper methods for hidden fields.
show all 3 replies

7 months ago

in Assignment 3, Milestone III on e168f08
Thanks.

7 months ago

in Assignment 3, Milestone III on e168f08
I seem to recall that it was mentioned in class that there was a way to check that an input field in the form is a number.
But after searching lecture 8, 9, 10 several times and and api.rubyonrails.com, I fail to find this.
I was looking under text_field.

If we really could do so, could you point me to the information. Thanks.
1 reply
xertroyt's picture
xertroyt It's a validation. Like all validations, it does not happen in the view markup (that is, not in text_field or any of the other helps).

Validations are declared on the model. I explained how these validations worked a few lectures ago.

If you will take a look at the Observation model in the latest download, you will see that the following has already been declared for you:

validates_numericality_of :amount

If you want to display the results of that validation, you will need to use the error display helpers -- for examples of that, see CCC or LinkWizz, or the lecture slides.

7 months ago

in Assignment 3, Milestone III on e168f08
okay, John. I will move on. I've spent too much time on this already. I will just comment out the destroy code.

The Session ID are not the same. One has 3 lines, the other 4. The 3rd line is different. I am not sure why one has a much longer ID.

I redirected to the correct page. The TA has seen that code at the time the problem appeared the first time. And this time, I didn't even do a deletion while adding in more observation_kind. But this IS strange.
1 reply
xertroyt's picture
xertroyt The session id in the log starts with the session id -- the extra stuff (e.g., "CkB1c2VkewY7CUY=--b6c94f16882989fe21d2a65e2858309809d2bab9") is an encoding of what is actually stored in your session. I am not 100% sure where the session id ends and the new data begins, but that is the way sessions work for the cookie store.

So: I don't think this has anything to do with your sessions.

Review your code for adding a measurement. Are you accidentally calling a method to delete a measurement?

I understand why you say, for instance, that you "redirected to the correct page." However, you have a bug, so it is futile to claim that your code is correct. You need to keep looking at it.

7 months ago

in Assignment 3, Milestone III on e168f08
Hi John,

Looks like my strange deletion problem is back. I really do see (something/someone) automatically deleting my observation_kind. While I was adding in a few measurement_kind (without deletion), one of them magically got deleted..

I have a snippet of the log when this happend. Would you be able to look at that. I have sent it to my TA as well. But in case you get a chance to look at it sooner, then I could proceed with the other part of the assignment.

I also noticed that in my log, there seems to be 2 sessionIDs:

Session ID: BAh7CToMdXNlcl9pZGkMOg1pc19hZG1pblQ6D3VzZXJfbG9naW4iCmFkbWlu
IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNo
ewY6C25vdGljZSIkWW91ciBraW5kIG9mIG1ldHJpY3MgaXMgY3JlYXRlZAY6
CkB1c2VkewY7CUY=--b6c94f16882989fe21d2a65e2858309809d2bab9

and

Session ID: BAh7CToMdXNlcl9pZGkMOg1pc19hZG1pblQ6D3VzZXJfbG9naW4iCmFkbWlu
IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNo
ewAGOgpAdXNlZHsA--be4e8371b9d302dd85b0ac0760e4566253c95e04

Either there are 2 sessions going on without me noticing (I only run 1 session at a time), or this is normal.
I use only 1 tab in the same browser as far as I know.

In any case, I didn't do any deletion during the session, and a row just disappeared.

Do you have any suggestion on where to look ? This problem has been going on, but it was intermitten.
1 reply
xertroyt's picture
xertroyt Those session id's like identical to me.

One thing that could be happening is that somewhere you are redirecting to the wrong page -- or, possibly, you are calling a method in your controller twice.

Why don't you go on to the other parts of the assignment anyway? I don't think you should let this hold you up.

7 months ago

in Assignment 3, Milestone III on e168f08
I have 2 questions:

(1) Is the UTC in your timestamp on your metricmine page printed by some specific time helper method.
I didn't find a particular simple method that prints out the time stamp the way you have it on our web pages.
I use for to_formatted_s (which does not have UTC, and it is not in UTC) time.
There were suggestions of strfttime...but they also, isn't exactly like yours ?

(2) My button looks different from yours. You have a blue button, and it is retangular. Mine has round edges. Is there a css style sheet we should use.
I already have one public/stylesheets/layout.css

Thanks
3 replies
Morris You should already have the correct stylesheets included, if you're starting with the contents of the downloaded zip file. All of the necessary stylesheets are in the public/stylesheets directory, and the default application layout file links to those stylesheets.
In the supplied material as I've downloaded it, the stylesheets directory contains 8 stylesheets, and the application layout in the layouts directory references 7 of them.

If you "view source" with your browser on any page that has a button, for example the users/login page, you can see the HTML for the rectangular blue button, and the corresponding .html.erb file for that view will show you the Rails code that generates that HTML.
Morris Re: the "UTC". It looks like if you just print out the value of a 'created_at' field, it comes out just right: the default format for ActiveSupport::TimeWithZone#to_s appears to be exactly what we want.
show all 3 replies
Returning? Login