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

Hello

<%=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

Welcome

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

On 23 April 2011 13:18, amrit pal pathak [email protected]
wrote:

Welcome

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 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

On 23 April 2011 13:40, amrit pal pathak [email protected]
wrote:

<%=link_to ‘Submit’%>
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).

Hello

<%=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

On Apr 23, 8:26am, Colin L. [email protected] wrote:

controller using “script/generate controller click fun”.Edited the app/
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).

Hello

<%=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

On 23 April 2011 16:48, amrit pal pathak [email protected]
wrote:


Now i gave plural ,again error

Hello

<%=link_to 'Submit',clicks_path %>

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

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

Colin

On Apr 23, 11:58am, Colin L. [email protected] wrote:

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”}

Thanks

On Apr 23, 10:11am, Colin L. [email protected] wrote:

controller using “script/generate controller click fun”.Edited the app/
actually want to do is link to a controller action from the view of
<%=link_to ‘Submit’,click_path%>

That should probably be clicks_path (plural).
Now i gave plural ,again error

Hello


<%=link_to ‘Submit’,clicks_path %>

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

Thanks

On 23 April 2011 17:04, amrit pal pathak [email protected]
wrote:

Error is
root /(.:format)
{:action=>“index”, :controller=>“home”}

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

On Apr 23, 5:04pm, amrit pal pathak [email protected]
wrote:

{: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

On Apr 23, 12:11pm, Frederick C. [email protected]
wrote:

{: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.

    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 C…

On 24 April 2011 06:45, amrit pal pathak [email protected]
wrote:

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??

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

On Apr 24, 2:52am, Colin L. [email protected] wrote:

click_fun GET /click/fun(.:format)
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??

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
OK
Thank you colin :stuck_out_tongue: