How to connect two controllers ?

I generated a simple controller using "script/generate controller form myfun".Then edited a /app/view/form/myfun.html.erb simply as <h1>Hello</h1> <%=link_to 'Submit'%>

                                               I created a another controller using "script/generate controller click fun".Edited the app/ view/click/fun.html.erb to hold a welcome message as

<h1>Welcome</h1>                                                       I want click on submit should show this message,but dont know how to connect these two controllers.using rails .I am using rails 3.0.7.

Please somebody guide me

Thanks

It is important to distinguish between the three components Model View Controller of MVC design. If you are not clear on these then some googling and reading might be worthwhile. I presume that what you actually want to do is link to a controller action from the _view_ of another controller. To do that simply put use link_to to link to the the controller/action that you want.

I think I suggested in a reply to one of your earlier questions (if it was you, apologies if not) that you worked right through some tutorials, the free to use online one at railstutorial.org is very good. Once you have done that then these very basic questions that you are asking will not need to be asked.

Colin

> I generated a simple controller using "script/generate controller form > myfun".Then edited a /app/view/form/myfun.html.erb simply as > <h1>Hello</h1> > <%=link_to 'Submit'%>

> I created a another > controller using "script/generate controller click fun".Edited the app/ > view/click/fun.html.erb to hold a welcome message as

> <h1>Welcome</h1> > I want click on > submit should show this message,but dont know how to connect these two > controllers.using rails .I am using rails 3.0.7.

It is important to distinguish between the three components Model View Controller of MVC design. If you are not clear on these then some googling and reading might be worthwhile. I presume that what you actually want to do is link to a controller action from the _view_ of another controller. To do that simply put use link_to to link to the the controller/action that you want.

            I add the link to click controller(it has a fun action) as ,but i gave error(may be a syntax error in specifying a controller path). <h1>Hello</h1> <%=link_to 'Submit',click_path%>

Help.

I think I suggested in a reply to one of your earlier questions (if it was you, apologies if not) that you worked right through some tutorials

Yes it was me.i read the tutorils and tried to understand.i am not a hard core programmer.i am a student sir,thats why asking these basic questions.

Thanks

> I generated a simple controller using "script/generate controller form > myfun".Then edited a /app/view/form/myfun.html.erb simply as > <h1>Hello</h1> > <%=link_to 'Submit'%>

> I created a another > controller using "script/generate controller click fun".Edited the app/ > view/click/fun.html.erb to hold a welcome message as

> <h1>Welcome</h1> > I want click on > submit should show this message,but dont know how to connect these two > controllers.using rails .I am using rails 3.0.7.

It is important to distinguish between the three components Model View Controller of MVC design. If you are not clear on these then some googling and reading might be worthwhile. I presume that what you actually want to do is link to a controller action from the _view_ of another controller. To do that simply put use link_to to link to the the controller/action that you want.

       I add the link to click controller\(it has a fun action\)

You are confusing controller and view again, you cannot add a link to a controller, only to a view.

as ,but i gave error(may be a syntax error in specifying a controller path). <h1>Hello</h1> <%=link_to 'Submit',click_path%>

That should probably be clicks_path (plural). If you run rake routes it will show you the routes you have defined, one of which will be something like clicks GET /clicks(.:format) {:controller=>"clicks", :action=>"index"} which will tell you that clicks_path is a valid route.

Colin

Now i gave plural ,again error     <h1>Hello</h1>    <%=link_to 'Submit',clicks_path %>

Error is undefined local variable or method `clicks_path' for #<#<Class: 0xb66b347c>:0xb66b1fa0>

Thanks

And the result from rake routes? You did try that didn't you?

Colin

i did it gives

  click_fun GET /click/fun(.:format) {:action=>"fun", :controller=>"click"} home_index GET /home/index(.:format) {:action=>"index", :controller=>"home"}       root /(.:format) {:action=>"index", :controller=>"home"}

Thanks

So why did you not say last time that the clicks routes are not there? If you have not got the routes setup then the _path variables will not be defined. I suggest you read the Rails Guide on Routing.

Colin

> And the result from rake routes? You did try that didn't you?

   i did it gives

click_fun GET /click/fun(.:format) {:action=>"fun", :controller=>"click"} home_index GET /home/index(.:format) {:action=>"index", :controller=>"home"} root /(.:format) {:action=>"index", :controller=>"home"}

This means that the URL helpers that exist are click_fun_path, home_index_path and root_path. You can use clicks_path because it doesn't exist.

Fred

It was path syntax error.Now i used        "<%=link_to 'Submit',click_fun_path %>" and it worked.          please tell me one thing ,click_fun_path is path to click controller or click view??

Thanks to colin and Frederick Cheung.

As I suggested previously it would be worth your while reading up on MVC architecture, as it is fundamental to Rails apps. There is no such thing as a link to a view, links are always to controller actions. Also as pointed out previously you can see that from the output of rake routes that you posted: click_fun GET /click/fun(.:format) {:action=>"fun", :controller=>"click"} That says that click_fun_path is a route with url click/fun (with optional format) which will run controller click, action fun.

Colin

OK Thank you colin :stuck_out_tongue: