Thursday, 15 July 2010

ruby on rails - Form_for method to another controller -



ruby on rails - Form_for method to another controller -

i have 2 controllers. pages , tasks. , in views/pages want create form tasks controller , new action.

i tried this:

<%= form_for @task, url: url_for(controller: 'tasks', action: 'new') |f| %> <%= f.text_field :content %> <%= f.submit "add" %> <% end %>

but error in browser:

first argument in form cannot contain nil or empty:

this how tasks controller's new method:

def new @task = task.new @task.done = false if @task.update_attributes(task_params) redirect_to root_path, notice: "success" else redirect_to root_path, notice: "error" end end

of course of study there isn't @task variable in pages/new. how tell rails variable in tasks controller?

your @task nil. should initialise in action view rendering or else utilize form_for task. should work. hope helps

ruby-on-rails ruby-on-rails-4

No comments:

Post a Comment