Skip to content

Instantly share code, notes, and snippets.

@Znow
Created April 30, 2012 10:00
Show Gist options
  • Save Znow/2556957 to your computer and use it in GitHub Desktop.
Save Znow/2556957 to your computer and use it in GitHub Desktop.
Started POST "/admin/tasks" for 127.0.0.1 at 2012-04-30 11:58:53 +0200
Processing by Admin::TasksController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6Rb8LRbmnOqdSUqQ+xJfyOHinwlLYThvfksXoTicIoQ=", "task"=>{"task_type"=>"Follow-up", "subject"=>"dsadsadsadsa", "responsible"=>"1", "client"=>"3", "deadline"=>"2012-04-30 11:58"}, "commit"=>"Save"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 2ms
ActiveRecord::AssociationTypeMismatch (Client(#70287180650000) expected, got String(#70287161020800)):
app/controllers/admin/tasks_controller.rb:25:in `new'
app/controllers/admin/tasks_controller.rb:25:in `create'
class Task < ActiveRecord::Base
attr_accessible :author, :deadline, :responsible, :subject, :task_type, :client
belongs_to :client
validates :task_type, :subject, :responsible, :deadline, :presence => true
end
module TaskHelper
def task_clients
client = Client.all
client.map{|c| [c.name, c.id] }
end
def task_responsibles
user = User.all
user.map{ |u| [u.name, u.id] }
end
def task_types
['Follow-up', 'Meeting', 'Email', 'Contract', 'Conference call', 'Note']
end
end
def create
@task = Task.new(params[:task])
@task.merge!(params[:author] => current_user)
@client_tasks = @task.client_tasks.create(client.id)
respond_to do |format|
if @task.save
flash[:success] = "<strong>Success!</strong> #{@task.subject} was successfully added.".html_safe
end
format.js { render :template => "admin/tasks/create.js.erb",
:locals => {
:task => @task,
:redirect_path => admin_tasks_path,
}
} # create.js.erb
end
end
@mjtko
Copy link

mjtko commented Apr 30, 2012

def create
    client = Client.find(params[:task].delete(:client))
    @task = Task.new(params[:task].merge(:author => current_user, :client => client))

    respond_to do |format|

Or:

def create
    client_id = params[:task].delete(:client)
    @task = Task.new(params[:task].merge(:author => current_user, :client_id => client_id))

    respond_to do |format|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment