Note that there are some explanatory texts on larger screens.

plurals
  1. PORails - passing session info in hidden fields - getting error
    primarykey
    data
    text
    <p>I'm trying to pass a project id from a session in a hidden field on a task form, so that when the task is created, it has the id of the project that it is assigned to. I've done this before fine, and have even tried copying over the code that I used from when it worked, but changing names and I'm getting errors no matter what I do - if anyone could help point out where I'm going wrong, it would be much appreciated, thanks!</p> <p>The error I'm getting with this configuration is: "unknown attribute: project_id"</p> <p>View Code (tasks/_form):</p> <pre><code>&lt;%= form_for(@task) do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.hidden_field :project_id, :value =&gt; session[:project_id] %&gt; &lt;/div&gt; ... &lt;% end %&gt; </code></pre> <p>Model Code (task):</p> <pre><code>attr_accessible :project_id belongs_to :project </code></pre> <p>Controller code (tasks_controller):</p> <pre><code>def new @task = Task.new @project_id = session[:project_id] respond_to do |format| format.html # new.html.erb format.json { render json: @task } end end def create project_id = session[:project_id] @task = Task.new(params[:task]) respond_to do |format| if @task.save format.html { redirect_to @task, notice: 'Task was successfully created.' } format.json { render json: @task, status: :created, location: @task } else format.html { render action: "new" } format.json { render json: @task.errors, status: :unprocessable_entity } end end end </code></pre> <p>Here's the application trace - it is pointing to line 46, which in my code is the '@task = Task.new(params[:task])' line in the create action...?</p> <pre><code>app/controllers/tasks_controller.rb:46:in `new' app/controllers/tasks_controller.rb:46:in `create' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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