Has_one, the = operator and validates_associated

Dear readers,

I am puzzles by the following, imagine models A and B. A has_one B and B
belongs_to A. So far so good. But rails does this great thing by
relfecting on this relationship and enables me use the equals sign to do
A.B=B. But now comes the puzzlement. Whenever you do this B is supposed
to be saved (see,
Peak Obsession).
Now a couple of questions, where do the errors go if one implemented a
validate method? I guess nowhere and they are ignored. Moreover if you
use ‘validates_associated :B’, which makes sense, you are forced to use
the equals sign method, which supposedly already saves the model (which
it actually doesn’t, I checked). So when is a instantiation of a model
really saved?

With kind regards,
Harm

Hello all,

Excuse me if I’ve got my terms incorrect (please correct me if so!).

I’ve created a partial for this blog application I’m writing, which
contains the following

<%= link_to post.title, :action => 'show', :id => post.title %>

Posted on <%= post.created_on.strftime("%d %b %Y @ %H:%M") %> by Alastair

<%= post.body %>

<% for tag in post.tags.split(" ") %> <%= link_to tag, :action => 'find', :id => tag %><% end %> tags| <%= link_to post.comments(:refresh).size, :action => 'show', :id => post.title, :anchor => "comments" %> comments

What I would like to do is depending on which action was called, write
out different code. So if the action was list or index, then write out

<%= link_to post.title, :action => 'show', :id => post.title %>

otherwise

<%= post.title %>

Simple but not knowing the ruby/rails terms, I’m struggling to find the
right search term in google!

Thanks in advance,

Alastair

Alastair M. wrote:

<%= post.body %>

<%= link_to post.title, :action => 'show', :id => post.title %>

otherwise

<%= post.title %>

Simple but not knowing the ruby/rails terms, I’m struggling to find the
right search term in google!

Ok, what I’ve since found out is using the render (:layout/:partial)
within the method. So I’m going to tinker around with that and see what
I come up with!

Alastair

Alastair M. wrote:

What I would like to do is depending on which action was called, write
out different code.

The name of the action is available in the view as params[:action]


We develop, watch us RoR, in numbers too big to ignore.

Mark Reginald J. wrote:

Alastair M. wrote:

What I would like to do is depending on which action was called, write
out different code.

The name of the action is available in the view as params[:action]

Ah thank you! even better