Question

My code has send s

    <% url = url_for(:controller => 'boxelements', :action => 'new', :project_id => @project.id, :author_id => User.current.id)  %>
    <%= link_to "Upload New File",url %>

from new method I can get the param values

    def new
      @boxelement = Boxelement.new
      puts params[:project_id]
      puts params[:author_id]
    end

Here is how I send this value as a form input

    <%= f.hidden_field :project_id, :value =>project_id %>
    <%= f.hidden_field :author_id, :value =>User.current.id %>

I need to access those value from create method of the controller

    def create
      @boxelement = Boxelement.new(params[:boxelement])

      if @boxelement.save
        puts params[:project_id] 
        puts params[:author_id]
      end
    end

This code shows nothing when they are in create method of controller.

    puts params[:project_id]
    puts params[:author_id]

What's wrong with my code?

Was it helpful?

Solution

From this line I can assume you want to access params of :boxelement

     @boxelement = Boxelement.new(params[:boxelement])

use the following line in order to access the params value.

 puts params[:boxelement][:project_id] 
 puts params[:boxelement][:author_id]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top