Ajax call, no route matches?

I’m trying to use an AJAX call in my code, but I doesn’t seem to be able
to find the method I’m trying to call, am I missing something really
obvious here??

I have a method dynamic_form in the TasksController class.

Here is the error I get back in the browser.

No route matches {:page=>nil, :escape=>false, :ascending=>nil,
:per_page=>nil, :group_filter=>“0”, :controller=>“tasks”, :tab=>nil,
:search=>{}, :action=>“dynamic_form”, :search_filter=>nil, :column=>nil}

Extracted source (around line #18):

15: <%= f.text_field :title %>
16: <%= f.hidden_field :assigned_to_id, :value => current_user.id %>
17:
18: Application:
19: <%= select ‘facet’, ‘value’,Facets.application_list([“GBOSS”,
“J_GMISEMEATC” ] ),{}, :onchange => remote_function(:url => {:action =>
‘dynamic_form’}) %>
20:
21: Issue Type:


Thanks for looking guys,

I’m sure the answer is something really obvious!

what route you have in form_for? does this happen when you submit the
form?

Radhames Brito wrote:

what route you have in form_for? does this happen when you submit the
form?

<%= form_for(@task, :task) do |f| -%>

Thanks

On Fri, Oct 8, 2010 at 12:05 PM, Paul H.e [email protected]
wrote:

Radhames Brito wrote:

what route you have in form_for? does this happen when you submit the
form?

<%= form_for(@task, :task) do |f| -%>

this wont build a route for the create action i think it should be

<%= form_for(@task) do |f| -%>

is either one or the other not both, you pass and instance or a symbol

also if this is rails 3 this wont be submited with ajax since it lacks
the
:remote=> true option
and in rails 2.3 it should be form_remote_for

also your controller should respond to js.

“No route matches {:page=>nil, :ascending=>nil, :escape=>false,
:per_page=>nil, :group_filter=>“0”, :tab=>nil, :controller=>“tasks”,
:search=>{}, :search_filter=>nil, :action=>“dynamic_form”,
:column=>nil}”

Something is wrong since the shouldnt be a passing :page=>nil,
:ascending=>nil,:per_page=>nil in the params , view the html code and
check
what action is been called in the html form tag, it should be calling
your_controller_name/dynamic_form (the path i gave you was for a restful
action like create and update not for a custom action like the one you
have,
sorry), what you have here is a custom action, but you can make it
restful
like this

resources :your_controller do
member do
get :dynamic_form <===== get since i assume this is a search
method
end
end

then you will have a new restful action and you can refer to it like
this

form_for dynamic_form_your_controller_path, :remote=> true do |f|

it will work, just remember to change your_controller with the actual
name of your controller, to make sure you can check it by typing rake
routes.

Something is wrong since the shouldnt be a passing :page=>nil,
:ascending=>nil,:per_page=>nil in the params , view the html code and
check
what action is been called in the html form tag, it should be calling
your_controller_name/dynamic_form (the path i gave you was for a restful
action like create and update not for a custom action like the one you
have,
sorry), what you have here is a custom action, but you can make it
restful
like this

Hi Radhames,

Its actually being called by the :onchange part of the form, using a
remote function call like this:

:onchange => remote_function(:url => {:action => ‘dynamic_form’}

Could i just assign values to the :page, :asceding and :per_page within
this call?

Thanks for your help so far, I’m sure the solution will prove to be
simple!!

Paul

On Oct 8, 4:41 pm, Paul H.e [email protected] wrote:

I’m trying to use an AJAX call in my code, but I doesn’t seem to be able
to find the method I’m trying to call, am I missing something really
obvious here??

What’s in your routes file? You may need to add the dynamic_form
action to the mapping defined there (see
http://guides.rubyonrails.org/routing.html#adding-more-restful-actions
or
http://guides.rubyonrails.org/v2.3.8/routing.html#adding-more-restful-actions)

Fred

Hi Radhames,

Thanks for your tips.

I changed to the <%= form_for(@task, :remote=> true) do |f| -%> format.
(I’m using rails3)

I also made sure my controller responds to js. I’m still getting the
same error:

“No route matches {:page=>nil, :ascending=>nil, :escape=>false,
:per_page=>nil, :group_filter=>“0”, :tab=>nil, :controller=>“tasks”,
:search=>{}, :search_filter=>nil, :action=>“dynamic_form”,
:column=>nil}”

Any other ideas?

Paul

Radhames Brito wrote:

On Fri, Oct 8, 2010 at 12:05 PM, Paul H.e [email protected]
wrote:

Radhames Brito wrote:

what route you have in form_for? does this happen when you submit the
form?

<%= form_for(@task, :task) do |f| -%>

this wont build a route for the create action i think it should be

<%= form_for(@task) do |f| -%>

is either one or the other not both, you pass and instance or a symbol

also if this is rails 3 this wont be submited with ajax since it lacks
the
:remote=> true option
and in rails 2.3 it should be form_remote_for

also your controller should respond to js.

:onchange => remote_function(:url => {:action => ‘dynamic_form’}

you should have said this in the first place, use jquery, with its live
function is the unobstrusive way, then sent a getscript, return js.erb
action.

If you need to now how to do this step by step, just have to post a bit
more
of your view code.

and the actions you want to call is can be access by
task_dynamic_form_path

What’s in your routes file? You may need to add the dynamic_form
action to the mapping defined there (see
http://guides.rubyonrails.org/routing.html#adding-more-restful-actions
or
http://guides.rubyonrails.org/v2.3.8/routing.html#adding-more-restful-actions)

Fred

Hi Fred,

I’ve tried various different things in my routes file.

At the moment, this is what it contains:

match ‘dynamic_form’ => ‘tasks#dynamic_form’

this is what rake routes gives back atm

task_dynamic_form /tasks/:task_id/dynamic_form(.:format)
{:controller=>“tasks”, :action=>“dynamic_form”}

Any help you might have is greatly appreciated!

Thanks,

Paul

Radhames Brito wrote:

If you need to now how to do this step by step, just have to post a bit
more
of your view code.

and the actions you want to call is can be access by
task_dynamic_form_path

Apologies Radhames, I did include it in my first post, but I guess i
could have been more clear!

Here is my view code. What it basically is supposed to do is run a
little bit of js that replaces some of html when the first drop down box
is changed.

<%= form_for(@task, :remote=> true, :as=>:task, :url => tasks_path )
do |f| -%>

<%= f.label :title, 'New task:' %> <%= f.text_field :title %> <%= f.hidden_field :assigned_to_id, :value => current_user.id %>

Application:
<%= select ‘facet’, ‘value’,Facets.application_list([“GBOSS”,
“J_GMISEMEATC” ] ),{}, :onchange => remote_function(:url => {:action =>
‘dynamic_form’} ) %>

Issue Type:
<%= select ‘task’, ‘issue_type’,
options_for_select(@task.sti_issue_type_list(User.current_user.group.id),
:selected => session[:default_task_issue_type]), {}, :onchange =>
“$(‘task_submit’).simulate(‘click’)” %>

<%= f.submit ‘Create’ %>
<% end -%>

“$(‘task_submit’).simulate(‘click’)” %>

This here is the problem this is calling url => tasks_path because is
working the same as the submit button and that is your index action
dynamic_form in never called your logic is not rigth, but am going out
to
lunch now all help you in
while

On Oct 11, 4:35 pm, Paul H.e [email protected] wrote:

I’ve tried various different things in my routes file.

At the moment, this is what it contains:

match ‘dynamic_form’ => ‘tasks#dynamic_form’

you’d want /tasks/dynamic form I think or the member {post
‘dynamic_form’} stuff - check the url that is generated

Fred

Hey guys,

I managed to resolve this one. It turns out the line i had inserted in
routes.rb was being affected by a ‘members’ statement before it, causing
it to generate the wrong route. I simply moved the line ahead of this to
resolve the issue, the AJAX call seems to work fine now.

Thanks for all your advice and tips,

Paul