After I thought this was fixed I found out that it wasn’t.
What i want to do is give the user the ability to add additional
text_fields
to their form.
I’ve created the calls and forms but let me show what’s going on:
In the form:
<%= link_to_remote “[+]”,
:update => ‘xtratitle’,
:url => {:action => “addtfield”}
%>
…
<% end %>
# here is the div for the
update
(which works when …keep reading)
In the controller -
def addtfield
render(:partial => ‘txtfield’)
end
So here is the where the problem seems to be:
In the controller I have a
before_filter :find_candidate
When it’s enabled - and I try the link_to_remote I get this error:
ActiveRecord::RecordNotFound in CanpositionsController#addtfield
Couldn’t find Candidate without an ID
If I disable the before_filter (which is obviously not the right
solution)
Then it gets me in the create or update code for not having the @candidate_id so db operations can’t take place.
I thought that since I was only adding a field into the form the form
should
handle this candidate_id , not sure.
Adding a field is a separate action, so you’re going to have to let
your controller know what you’re doing. Add :candidate_id => @candidate.id in your :url hash, change your before_filter to not
include the addtfield action, use the session or flash, do something.
And I don’t know the specifics of your page layout, but keep in mind
that update means replace_html. If you want to append something, use
:position.
Thank you Yossef.
It is working now , however I believe adding the candidate_id to the
link_to_remote hash has any effect
url => {:action => “addtfield”, :candidate_id => @candidate.id}
I only say that cause I added a condition in the action based on the
candidate_id and it had no effect.
Unless I need to add more braces , which I haven’t tried yet.