1
0

More than 5 years have passed since last update.

How to make a relationship between ticket and current_user.

Last updated at Posted at 2012-03-16

At first , you should write belongs_to :user in ticket model.
And use merge! method to make a relationship between ticket and current_user in create action of tickets_controller.

  def create
    @ticket = @project.tickets.build(params[:ticket].merge!(:user => current_user))
    if @ticket.save
      flash[:notice] = "Ticket has been created."
      redirect_to [@project,@ticket]
    else
      flash[:alert] = "Ticket has not been created."
      render :action => "new"
    end
  end

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0