Two buttons respond to same action

Hey

I am using rails 3.0.7.I created two buttons simply as:

<%= button_to “Great”, :action => “click”%>

<%= button_to “click me”, :action => “work”%>

Router.rb file looks like:

Check::Application.routes.draw do

get “gne/clg”

get “posts/index”

resources :posts do

end

#get ‘posts/click’

ActionController::Routing::Routes.draw do |map|

map.root :controller => “posts”, :action => “click”

end

ActionController::Routing::Routes.draw do |map|

map.root :controller => “posts”, :action => “work”

end

end

When i click any button both respond to /app/view/posts/click.html.erb while i have another file work.html.erb in same directory for other button .Whats problem may be?

Amrit

Hey I am using rails 3.0.7.I created two buttons simply as: <%= button_to "Great", :action => "click"%> <%= button_to "click me", :action => "work"%>

Router.rb file looks like:

Check::Application.routes.draw do # get "gne/clg"

get "posts/index" resources :posts do end #get 'posts/click'

ActionController::Routing::Routes.draw do |map| map.root :controller => "posts", :action => "click" end

ActionController::Routing::Routes.draw do |map| map.root :controller => "posts", :action => "work" end end

First off you don't need that ActionController::Routing::Routes.draw stuff if you use the rails 3 syntax. root :to => "posts#click"

Secondly you're mapping both your actions to the same path - you need to map them to different paths if you want rails to know which action to route to when the request arrives.

Fred

Fred

Third please stop posting the same question as two different people (John S Shelfer and Amritpal Pathak). Use one email address and one identity then wait for someone to respond.

B.

I had not realised till just now that John Shelfer is also Amritpal Pathak that has caused so much strain on our patience in the past. I think he/she is a wind up merchant just getting us all to waste our time.

Colin

I had not realised till just now that John Shelfer is also Amritpal Pathak

oops! I thought you were just being *really* patient...

I think he/she is a wind up merchant just getting us all to waste our time.

+1

Ok

Hey

  I am using rails 3.0.7.I created two buttons simply as:
 <%= button_to "Great", :action => "click"%>
 <%= button_to "click me", :action => "work"%>

Router.rb file looks like:

Check::Application.routes.draw do

get “gne/clg”

get “posts/index”

resources :posts do

end

#get ‘posts/click’

ActionController::Routing::Routes.draw do |map|

map.root :controller => “posts”, :action => “click”

end

ActionController::Routing::Routes.draw do |map|

map.root :controller => “posts”, :action => “work”

end

end

First off you don’t need that ActionController::Routing::Routes.draw

stuff if you use the rails 3 syntax.

root :to => “posts#click”

Thanks for help.It worked.

Secondly you’re mapping both your actions to the same path - you need

to map them to different paths if you want rails to know which action

to route to when the request arrives. Can you tell please how to map both actions to different paths.I

am new to rails so dont know OR any good tutorial that can help.

I think I can speak for most people (yeah notice the most, didnt want to speak for everybody) here in saying, no we cant.

This should be everyone’s starting point when first learning about Rails routing: http://guides.rubyonrails.org/routing.html

Read it a couple of times at least. If you’re still unsure, at least you’ll have enough context to come back and ask specific questions about the parts you don’t understand.

This should be everyone’s starting point when first learning about Rails routing: http://guides.rubyonrails.org/routing.html

Read it a couple of times at least. If you’re still unsure, at least you’ll have enough context to come back and ask specific questions about the parts you don’t understand.

Ok chris.Thank you very much.

resources :posts do

member do

get ‘click’

end

end

But it still gave routing error

No route matches {:controller=>“posts”, :action=>“click”}

Thank you

It seems clear from posts recently that Amritpal Pathak and John Shelfer are one and the same. He has been posting the same questions under both names. Readers may find it interesting to read

where he posts under both aliases, thanking himself for support. It is clear that the guy is not genuine.

I think you will have to get yourself a new name John/Amritpal

Colin

This should be everyone’s starting point when first learning about Rails

routing: http://guides.rubyonrails.org/routing.html

Read it a couple of times at least. If you’re still unsure, at least

you’ll have enough context to come back and ask specific questions about the

parts you don’t understand.

I followed Section 2.9.1 for adding a route to single action of

controller as:

     resources :posts do
    member do
    get 'click'
    end
    end
                                 But it still gave routing error
       No route matches {:controller=>"posts", :action=>"click"}

Thank you

It seems clear from posts recently that Amritpal Pathak and John

Shelfer are one and the same. He has been posting the same questions

under both names. Readers may find it interesting to read

http://www.ruby-forum.com/topic/1610794

where he posts under both aliases, thanking himself for support. It

is clear that the guy is not genuine.

I only posted one question twice from both aliases.The reason was when i posted it from amrit aliase due to any network problem or something else ,it didn’t show at mailing list.So i was worried and posted it from other aliase too. I apologize for it.Next time i will careful about it.

Can you explain then why in "uninitialized constant PostsController::Post" - Rails - Ruby-Forum when I said "Am I the only one thinking this poster is winding us up?" referring to yourself as Amrit that yourself as John replied " Not at all.He is new to Rails So I think we should help him to resolve the issue." and you as Amrit then replied again "Thank you for your support sir".

Colin

Readers may find it interesting to read "uninitialized constant PostsController::Post" - Rails - Ruby-Forum where he posts under both aliases, thanking himself for support.

Good effort. I'd forgotten about that thread (there were so many...)

It is clear that the guy is not genuine.

I don't think he's necessarily taking the p***, but he's certainly not putting in the effort (or is not able to?) to work towards solving his own problems. How many times have you and others said "rake routes"? Remembering previous advice is essential to building skills, and learning where to find stuff out for oneself (again... I've never seen so many URLs pointing to the routing guides as have been in Amritpal/John threads) means you don't have to keep wasting peoples' time with the same questions.

I request to all of you please give me a chance to prove myself.

Thank you.

This should be everyone’s starting point when first learning about

Rails

routing: http://guides.rubyonrails.org/routing.html

Read it a couple of times at least. If you’re still unsure, at least

you’ll have enough context to come back and ask specific questions

about the

parts you don’t understand.

I followed Section 2.9.1 for adding a route to single action of

controller as:

     resources :posts do
    member do
    get 'click'
    end
    end
                                 But it still gave routing error
       No route matches {:controller=>"posts", :action=>"click"}

Thank you

It seems clear from posts recently that Amritpal Pathak and John

Shelfer are one and the same. He has been posting the same questions

under both names. Readers may find it interesting to read

http://www.ruby-forum.com/topic/1610794

where he posts under both aliases, thanking himself for support. It

is clear that the guy is not genuine.

I only posted one question twice from both aliases.The reason was when i

posted it from amrit aliase due to any network problem or something else ,it

didn’t show at mailing list.So i was worried and posted it from other aliase

too.

Can you explain then why in http://www.ruby-forum.com/topic/1610794

when I said “Am I the only one thinking this poster is winding us up?”

referring to yourself as Amrit that yourself as John replied " Not at

all.He is new to Rails So I think we should help him to resolve the

issue." and you as Amrit then replied again "Thank you for your

support sir".

Yes .You are right colin.I did this mistake .I replied from both aliases here because i hadn’t want to create an issue(Guilt was mine ).So to terminate the thread i did it.NOw i ensure you ,it will not happen again.

I request to all of you please give me a chance to prove myself.

Thank you.

Use the troubleshooting skills that everyone has been teaching you. They’ve given you advice on how to check for why you can’t see that route and learn more about it. Demonstrate that you are learning from that advice. That is how you earn that chance.

B.