Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You ask about debugging, so the first step may be looking at the server log (log/development.log).</p> <p>There you should see the "params" hash. Maybe your params contain "activity"=>{"client_id"=>..} instead of "client_id"=>.. ?</p> <p>Also look at the generated HTML page - use a Firebug or just use a "view source" method of your browser. Look, especially, for input names.</p> <p>If everything looks OK, put a few debug calls in your action, and look at the development.log for some database activity - do the SQL queries look like they are doing what you want?</p> <p>In your question there is no 'save' method. The 'build' method does NOT save the created record. Maybe this is your problem?</p> <pre><code>def add_client logger.debug "Creating Activity" @activity = IndividualActivity.new(session[:individual_activity]) logger.debug "Building clientship" # Refresh client @activity.clientships.build(:client =&gt; Client.find(params[:client_id])) logger.debug "@activity = #{@activity.inspect}" # Maybe you were missing this part of code? logger.debug "Saving @activity" @activity.save! # use a ! to easily see any problems with saving. # Remove in production and add a proper if logger.debug "Saved. @activity = #{@activity.inspect}" respond_to do |format| format.js end end </code></pre> <p>You should create a functional test (in case you haven't already) and ensure that if you send proper parameters, your action works as intended.</p> <p>The test will narrow your search. If the test fails, you know you have a problem in the action. If the test is OK, you need to ensure the parameters are sent properly, and you probably have the problem in your view.</p> <p><strong>UPDATE</strong>: You said you have TWO forms on the page. This may be the problem, since only one form may be sent at a time. Otherwise it would need to work in a way which can send two requests in one request.</p> <p>First thing (useful in all similar problems): <em>validate whether your page has correct HTML structure</em> - for example <a href="http://validator.w3.org" rel="nofollow">http://validator.w3.org</a> would be a good start. Try to make the code validate. I know that some people treat a "green" status as a unachievable mastery, but just it's really not so hard. With valid code you may be sure that the browser really understands what you mean.</p> <p>Second: Place all your inputs in a single form. You have problems with nested attributes. For start, try to manually insert inputs with name like <code>&lt;input name="activity[clientship_attributes][0][name]" value="John"/&gt;</code>, and for existing clientships ensure that there is an input with name = <code>activity[clientship_attributes][0][id]</code>. This is the way nested attributes are handled.</p> <p>Your view may create such fields automagically. This construction should be what you need: (it worked in one of my old project in rails 2.x, I have just replaced the names with ones you use)</p> <pre><code>&lt;% form_for(@activity) do |f| %&gt; &lt;p&gt;&lt;%= f.text_field :activity_something %&gt;&lt;/p&gt; &lt;% @activity.clientships.each do |clientship| %&gt; &lt;% f.fields_for :clientships, clientship do |cform| %&gt; &lt;p&gt;&lt;%= cform.text_field :name %&gt;&lt;/p&gt; &lt;p&gt;&lt;%= cform.text_fiels :something %&gt;&lt;/p&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>If you really want to use a partial there, don't create a new form in the partial. Use only the parts of above code.</p> <p>To pass a variable to the partial, use :locals attribute in the place where you call render :partial:</p> <pre><code>&lt;%= render :partial =&gt; 'clientship', :locals =&gt; {:form =&gt; f} %&gt; </code></pre> <p>Then, in your partial, you may use a local variable <code>form</code> where you would use <code>f</code> outside of the partial. You may, of course, map the variables to the same name: <code>:locals =&gt; {:f =&gt; f}</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload