Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible to add a form into another models view in rails
    text
    copied!<p>I have a very small application I ma building in rails. It is a simple weight tracker app. I have created a <code>User</code> model which has a sign up page. Once the user logs in they are redirected to the <code>user#show</code> view. Here is the user controller so far:</p> <pre><code>class UsersController &lt; ApplicationController before_filter :authenticate_user! def show @user = current_user end end </code></pre> <p>I have 2 other models one is a <code>Weight</code> model and the other a <code>Goal</code> model, I would like it so what when a user signs up they are presented with a screen asking them to type in the current weight and goal weight this information will then be store in the <code>Weight</code> and <code>Goal</code> models respectively along with the logged in users ID.</p> <p>So far I have been able to add a form to the user <code>show.html.erb</code> template :</p> <pre><code>&lt;%= form_for @user do |f| %&gt; &lt;%= f.fields_for :weight do |builder| %&gt; &lt;fieldset&gt; &lt;%= f.label :value, "Current weight" %&gt;&lt;br /&gt; &lt;%= f.text_field :value %&gt;&lt;br /&gt; &lt;/fieldset&gt; &lt;% end %&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Which renders the form correctly but when I then click on the submit button it simply goes to an error page saying <code>Unknown action- The action 'update' could not be found for UsersController</code>. Im assuming iM doing something wrong as it should try and send to the create action. </p> <p>Is there anyone out there who could help me back on the right path, Im very much a noob at rails.</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