Routing generated paths in Ruby on Rails -
I'm making a start in Ruby-on-Rail and I tried to do my work last time:
I have a Ruby-on-Rail application - blog with posts and categories. I have to have another URL for posts (I want to do http: // localhost: 3000 / posts
instead of http: // localhost: 3000 / news
) First I tried to change the controller and the sections of the post
to news
, but I left (due to non-singular singular-plural form). Then in my place map.resources: posts
(case 1) to
map.resources: news ,: admin = & gt; "Post" #case2
or
map.resources: posts, as in => As I watched "News" # EK3
in routes.rb
. It does not work either.
How can I do this?
Edit:
The output of the rake routes is
(only the first lines):
Case 1 and 3 To:
posts / posts {: action => "Index",: admin = & gt; "Post"} Formatted_Posts / Pastes: Format {: Action => "Index" ,: admin = & gt; "Post"} Post / Post {: Action => "Create",: admin = & gt; "Post"} POST / POSTS: format {: action = & gt; "create",: admin = & gt; "post"} new_post gET / posts / new {: action = & gt; & Gt; "posts"} "/ edit / post /: id / edit {: action =>" edit ",:" API "," administrator => "Post"} formatted_edit_post receive / posts /:id/edit.:format {: ADC => "Edit",: Controller => "Post"} Post GET / Post / Id: ADI: Action => "Show",: Controller => "Post"} Formatted_post Received / Post / Id:: Format {: Action => "Show",: Controller => "Post"} Press / post /: id {: action = & gt; "Update",: admin = & gt; "Posts"} PUT / posts /: id :: format {: action => "Update",: admin = & gt; "Post"} delete / post / id: {action = & gt; "Destroyed" ,: controller => "Post"}
edition =: format {: action => "Delete",: admin = & gt; "Post"}
Output for case 2:
news_index gET / news {: action = & gt; "Index" ,: admin = & gt; "Post"} formatted_news_index GET /news.:format {: action => "Index" ,: admin = & gt; "Post"} Post / News {: action = & gt; "Create" ,: admin = & gt; "Post"} POST /news.:format {: action = & gt; "Create" ,: admin = & gt; "Posts"} new_news GET / news / New {: action = & gt; "New" ,: admin = & gt; "Posts"} formatted_new_news GET /news/new.:format {: action => "New" ,: admin = & gt; "Posts"} edit_news GET / news /: id / edit {: action = & gt; "Edit",: admin = & gt; "Posts"} formatted_edit_news GET /news/:id/edit.format {: action => "Edit",: admin = & gt; "Post"} news / news / id: id {: action => "Show",: Controller => "Post"} formatted_news GET / news /: id. :: format {: action = & gt; "Show",: Controller => "Post"} PUT / news /: id {: action = & gt; "Update",: admin = & gt; "Posts"} PUT /news/:id.:format {: action => "Update" ,: Admin = & gt; "Post"} delete / news / id:: id {: action => "Destroyed" ,: controller => "Post"} Delete / News / ID: I do not have any errors in my format, because I do not have my source code
code> edit_news , I have for example and & lt;% = link_to 'edit', edit_post_path (post)% & gt; ;
Your first step was good: all posts (places) * news to classes * classes Change in Calling your model news and controller newscountry should not be a problem.
Note : Do not forget to restart your webserver.
Comments
Post a Comment