I create a new archiv.html.erb and a archiv method in the controller.
Now, I would like to link from index.html.erb to archiv.html.erb. I
tried to use <%= link_to 'archive', archiv_xxx_path %> but it doesn't
run.
It appears a error message "SyntaxError in xxx#index".
Hi,
You can use <%= link_to 'archive', :action => 'archive' %> in the view.
Then define an action in your controller. To do this, all you need is:
def archive
end
This will automatically go to a page titled "archive" in your
controller's view, ex: archive.rhtml
That I'm not so sure on... Is your action defined in a different
controller? If so, you can use:
<%= link_to 'action', :controller => 'ControllerName', :action =>
'ActionName' %>
Hope it helps... Other than that, I don't know what that error is...
No, both methods are in the same controller - so I don't need the
:controller statement.
In the new version of rails (2.0), I can use for example <%= link_to
'show', show_xxx_path %>. Why can't I use the same principle with the
archive? I want to use <%= link_to 'archive', archiv_xxx_path %> but it
doesn't run!
hmmm... I'm pretty new at RoR, so I'm not sure about this, but have you
tried naming it something other than "archive"? Perhaps it is a built-in
method or class or something that is throwing off your statement. Try
"archive_data" or something.
sorry, but it isn't a problem with the naming convention. When I put an
id behind the url, then the application runs. For example:
http://localhost:3000/xxx/archive/1 but with
http://localhost:3000/xxx/archive it appears a error message. So I must
change the routes.rb but I don't know how...
Now when I use http://localhost:3000/xxx/archive the interpreter means,
that archive is an id and not a method.
... Rails rails assumes that you are calling the 'show' action on the
'xxx' controller with 'archiv' as the ID of the model instance to be
shown.
To get rails to understand that 'archiv' is a new action, you need to
edit the routes.rb file and add appropriate routes using either
the :collection option (if the archiv action works with a collection
of model instances) or with the :member option (if you are working
with only one instance of the model).
Check out the screencasts below for a quick intro to routes and custom
actions