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, http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000472). 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 -- Posted via http://www.ruby-forum.com/.
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
<h2><%= link_to post.title, :action => ''show'', :id
=> post.title %></h2>
<h4>Posted on <%= post.created_on.strftime("%d %b %Y @
%H:%M") %> by
Alastair</h4>
<div><%= post.body %></div>
<p>
<span id="tags"><% for tag in post.tags.split(" ")
%> <%= link_to tag,
:action => ''find'', :id => tag %><% end %>
tags</span>|
<span id="tags"><%= link_to post.comments(:refresh).size,
:action =>
''show'', :id => post.title, :anchor =>
"comments" %> comments</span>
</p>
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
<h2><%= link_to post.title, :action => ''show'', :id
=> post.title %></h2>
otherwise
<h2><%= post.title %></h2>
Simple but not knowing the ruby/rails terms, I''m struggling to find the
right search term in google!
Thanks in advance,
Alastair
Alastair Moore wrote:> 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 > > <h2><%= link_to post.title, :action => ''show'', :id => post.title %></h2> > <h4>Posted on <%= post.created_on.strftime("%d %b %Y @ %H:%M") %> by > Alastair</h4> > <div><%= post.body %></div> > <p> > <span id="tags"><% for tag in post.tags.split(" ") %> <%= link_to tag, > :action => ''find'', :id => tag %><% end %> tags</span>| > <span id="tags"><%= link_to post.comments(:refresh).size, :action => > ''show'', :id => post.title, :anchor => "comments" %> comments</span> > </p> > > 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 > > <h2><%= link_to post.title, :action => ''show'', :id => post.title %></h2> > > otherwise > > <h2><%= post.title %></h2> > > 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 Moore 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 James wrote:> Alastair Moore 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