I am in the process of still learning Rails 3 but routes are driving me crazy. I am trying to use a namespace to separate an administration section of the site. Problem is that some things in the namespace simply don't work and also route to the wrong place. For example using rails generated routes by specifying a resource the view points to the wrong route when passed an object so the edit form won't work.
Links with link_to don't work either even when the route does exist it says it doesn't. Firstly here is the namespaced routes output from rake routes.
namespace :admin do
resources :users
end
admin_users GET /admin/users(.:format) {:action=>"index", :controller=>"admin/users"}
POST /admin/users(.:format) {:action=>"create", :controller=>"admin/users"}
new_admin_user GET /admin/users/new(.:format) {:action=>"new", :controller=>"admin/users"}
edit_admin_user GET /admin/users/:id/edit(.:format) {:action=>"edit", :controller=>"admin/users"}
admin_user PUT /admin/users/:id(.:format) {:action=>"update", :controller=>"admin/users"}
DELETE /admin/users/:id(.:format) {:action=>"destroy", :controller=>"admin/users"}
Controller:
class Admin::UsersController < ApplicationController
def index
#users = User.all
end
def show
#user = User.find(params[:id])
end
def new
#user = User.new
end
def edit
#user = User.find(params[:id])
end
def create
#user = User.new(params[:user])
if #user.save
redirect_to(#user, :notice => 'User was successfully created.')
else
render :action => "new"
end
end
def update
#user = User.find(params[:id])
if #user.update_attributes(params[:user])
redirect_to(admin_users_path, :notice => 'User was successfully updated.')
else
render :action => "edit"
end
end
def destroy
#user = User.find(params[:id])
#user.destroy
redirect_to(admin_users_path)
end
end
Example view: index.html.erb listing all users
<h1>Listing users</h1>
<table>
<% for user in #users %>
<tr>
<td><%= user.id %></td>
<td><%= user.username %></td>
<td><%= user.email %></td>
<td><%= link_to 'Show', #user %></td>
<td><%= link_to 'Edit', edit_admin_user_path(user) %></td>
<td><%= link_to 'Destroy', admin_user_path, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New User', new_admin_user_path %>
Using the edit view is also having a problem. The edit form should point to the update route but does not. Instead it points to the edit route (basically itself) when only being passed a User object. From what I have been reading using an object in forms is the recommended way but this cant be a good thing if it does not work.
I get this error on listing all users page.
No route matches {:action=>"update", :controller=>"admin/users"}
Extracted source (around line #17):
17: <td><%= link_to 'Destroy', admin_user_path, :confirm => 'Are you sure?', :method => :delete %></td>
I am so trying to persevere but this is driving me loopy. FYI: Yes I know there are authentication frameworks out there but I am trying to make one from scratch. This is a learning experience and as such just using gems and plugins willy nilly is not the way to go in my opinion.
Thank you
Onyth
You're missing the id in the delete link
Try with
<td><%= link_to 'Destroy', admin_user_path(user), :confirm => 'Are you sure?', :method => :delete %></td>
(changed admin_user_path to admin_user_path(user) as the link)
If you do a rake routes you would see something like this:
admin_users GET /admin/users(.:format) {:controller=>"admin/users", :action=>"index"}
POST /admin/users(.:format) {:controller=>"admin/users", :action=>"create"}
new_admin_user GET /admin/users/new(.:format) {:controller=>"admin/users", :action=>"new"}
edit_admin_user GET /admin/users/:id/edit(.:format) {:controller=>"admin/users", :action=>"edit"}
admin_user GET /admin/users/:id(.:format) {:controller=>"admin/users", :action=>"show"}
PUT /admin/users/:id(.:format) {:controller=>"admin/users", :action=>"update"}
DELETE /admin/users/:id(.:format) {:controller=>"admin/users", :action=>"destroy"}
admin_pages GET /admin/pages(.:format) {:controller=>"admin/pages", :action=>"index"}
POST /admin/pages(.:format) {:controller=>"admin/pages", :action=>"create"}
new_admin_page GET /admin/pages/new(.:format) {:controller=>"admin/pages", :action=>"new"}
edit_admin_page GET /admin/pages/:id/edit(.:format) {:controller=>"admin/pages", :action=>"edit"}
admin_page GET /admin/pages/:id(.:format) {:controller=>"admin/pages", :action=>"show"}
PUT /admin/pages/:id(.:format) {:controller=>"admin/pages", :action=>"update"}
DELETE /admin/pages/:id(.:format) {:controller=>"admin/pages", :action=>"destroy"}
So you can derive
admin_user_path
which would be the same as
user_path
Then you would pass the #user in admin_user_path like so:
admin_user_path(#user)
The :method should then call the destroy method instead of going to the show method automatically! :)
To get the form_for working, I found the following resource: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for
Under the form_for section, they explain namespace routing with form_for as:
For namespaced routes, like admin_post_url:
<%= form_for([:admin, #post]) do |f| %>
...
<% end %>
For information regarding rake routes check out: http://guides.rubyonrails.org/command_line.html#rake-is-ruby-make then under section 2.4.9 Miscellaneous Tasks they explain rake --tasks shows you various rake commands that you can use and rake routes shows you route paths available.
Hope this helps!
Related
In my Rails 4 app, there are four models:
class User < ActiveRecord::Base
has_many :administrations
has_many :calendars, through: :administrations
end
class Calendar < ActiveRecord::Base
has_many :administrations
has_many :users, through: :administrations
has_many: :posts
end
class Administration < ActiveRecord::Base
belongs_to :user
belongs_to :calendar
end
class Post < ActiveRecord::Base
belongs_to :calendar
end
With this routing:
Rails.application.routes.draw do
root to: 'pages#home'
devise_for :users, :path => 'account'
resources :calendars do
resources :posts, shallow: true
end
end
Which gives these routes:
Prefix Verb URI Pattern Controller#Action
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
root GET / pages#home
new_user_session GET /account/sign_in(.:format) devise/sessions#new
user_session POST /account/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /account/sign_out(.:format) devise/sessions#destroy
user_password POST /account/password(.:format) devise/passwords#create
new_user_password GET /account/password/new(.:format) devise/passwords#new
edit_user_password GET /account/password/edit(.:format) devise/passwords#edit
PATCH /account/password(.:format) devise/passwords#update
PUT /account/password(.:format) devise/passwords#update
cancel_user_registration GET /account/cancel(.:format) devise/registrations#cancel
user_registration POST /account(.:format) devise/registrations#create
new_user_registration GET /account/sign_up(.:format) devise/registrations#new
edit_user_registration GET /account/edit(.:format) devise/registrations#edit
PATCH /account(.:format) devise/registrations#update
PUT /account(.:format) devise/registrations#update
DELETE /account(.:format) devise/registrations#destroy
user_confirmation POST /account/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /account/confirmation/new(.:format) devise/confirmations#new
GET /account/confirmation(.:format) devise/confirmations#show
user_unlock POST /account/unlock(.:format) devise/unlocks#create
new_user_unlock GET /account/unlock/new(.:format) devise/unlocks#new
GET /account/unlock(.:format) devise/unlocks#show
calendar_posts GET /calendars/:calendar_id/posts(.:format) posts#index
POST /calendars/:calendar_id/posts(.:format) posts#create
new_calendar_post GET /calendars/:calendar_id/posts/new(.:format) posts#new
GET /posts/:id/edit(.:format) posts#edit
GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
calendars GET /calendars(.:format) calendars#index
POST /calendars(.:format) calendars#create
new_calendar GET /calendars/new(.:format) calendars#new
edit_calendar GET /calendars/:id/edit(.:format) calendars#edit
calendar GET /calendars/:id(.:format) calendars#show
PATCH /calendars/:id(.:format) calendars#update
PUT /calendars/:id(.:format) calendars#update
DELETE /calendars/:id(.:format) calendars#destroy
And finally, here is the content of posts_controller.rb:
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
# GET /posts
# GET /posts.json
def index
#posts = Post.all
end
# GET /posts/1
# GET /posts/1.json
def show
end
# GET /posts/new
def new
#post = Post.new
end
# GET /posts/1/edit
def edit
end
# POST /posts
# POST /posts.json
def create
#calendar = Calendar.find(params[:calendar_id])
#post = #calendar.posts.create(post_params)
respond_to do |format|
if #post.save
format.html { redirect_to calendar_path(#calendar), notice: 'Post was successfully created.' }
format.json { render :show, status: :created, location: #post }
else
format.html { render :new }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /posts/1
# PATCH/PUT /posts/1.json
def update
respond_to do |format|
if #post.update(post_params)
format.html { redirect_to calendar_path, notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: #post }
else
format.html { render :edit }
format.json { render json: #post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
#calendar = Calendar.find(params[:calendar_id])
#post.destroy
respond_to do |format|
format.html { redirect_to calendar_path(#calendar), notice: 'Post was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
#post = Post.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def post_params
params.require(:post).permit(:date, :time, :subject, :format, :copy, :media)
end
end
I keep running into a similar error.
Issue #1: when I try to delete a post from the show.html.erb calendar view:
<h2><%= #calendar.name %> Calendar</h2>
<h3>Posts</h3>
<% if #calendar.posts.any? %>
<table>
<tr>
<th>Date</th>
<th>Time</th>
<th>Subject</th>
<th>Format</th>
<th>Copy</th>
<th>Media</th>
</tr>
<% #calendar.posts.each do |post| %>
<tr>
<td><%= post.date %></td>
<td><%= post.time %></td>
<td><%= post.subject %></td>
<td><%= post.format %></td>
<td><%= post.copy %></td>
<td><%= post.media %></td>
<td><%= link_to 'View', post %></td>
<td><%= link_to 'Update', edit_post_path(post) %></td>
<td><%= link_to 'Delete', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
</table>
<% end %>
...
I get:
ActiveRecord::RecordNotFound in PostsController#destroy
Couldn't find Calendar with 'id'=
Issue #2: when I try to update a post from the edit.html.erb post view:
<h1>Editing Post</h1>
<%= render 'form' %>
<%= link_to 'Show', #post %> |
<%= link_to 'Back', posts_path %>
I get:
ActiveRecord::RecordNotFound in PostsController#update
Couldn't find Calendar with 'id'=
Issue #3: when I try to go back to the show.html.erb calendar view from the show.html.erb post view:
<div>
<p>Date</p>
<%= #post.date %>
</div>
<div>
<p>Time</p>
<%= #post.time %>
</div>
<div>
<p>Subject</p>
<%= #post.subject %>
</div>
<div>
<p>Format</p>
<%= #post.format %>
</div>
<div>
<p>Copy</p>
<%= #post.copy %>
</div>
<div>
<p>Media</p>
<%= #post.media %>
</div>
<%= link_to 'Edit', edit_post_path(#post) %> |
<%= link_to 'Back', posts_path %>
I get:
ActiveRecord::RecordNotFound in PostsController#show
Couldn't find Calendar with 'id'=
If my interpretation of the errors is correct, every time, the problem seems to be that I cannot retrieve the id of the calendar the post belongs to.
In other words, I cannot retrieve the parent (calendar) id from the child (post) controller.
I believe this is a problem related to my nested shallow resources and the way my links are built in the views.
I can't figure out how to make these links work.
If you could provide me with the solution — and most importantly the reasoning — for one of the three situations described above, I would most definitely be able to come up with the solution for the other two.
Any idea?
I found a solution to each one of my three issues.
Issue #1: I replaced:
format.html { redirect_to calendar_path(#calendar), notice: 'Post was successfully destroyed.' }
with:
format.html { redirect_to calendar_path(#post.calendar_id), notice: 'Post was successfully destroyed.' }
in posts_controller.rb.
Issue #2: I replaced:
<%= link_to 'Back', posts_path %>
with:
<%= link_to 'Back', calendar_path(#post.calendar_id) %>
in the edit.html.erb posts view.
Issue #3: I replaced:
<%= link_to 'Back', posts_path %>
with:
calendar_path(#post.calendar_id)
in the show.html.erb posts view
Mamboo!
Am new to RoR and using Lynda Ruby on Rails 4 Essential Training.
I keep getting " Unknown Action, The action '1' could not be found for SubjectsController" After pressing "Update Subject", on my edit page. I think it can not find update function! What is missing here?
Route.rb
Rails.application.routes.draw do
resources :subjects do get 'index', on: :collection end
match ':controller(/:action(/id))', :via => [:get, :post]
end
subjects_controller.rb
class SubjectsController < ApplicationController
layout false
def index
#subjects = Subject.sorted
end
def show
#subject = Subject.find(params[:id])
end
def new
#subject = Subject.new({:name => "Default"})
end
def create
#subject = Subject.new(subject_params)
if #subject.save
flash[:notice] = "Subject Created Successfully"
redirect_to(:action => 'index')
else
render('new')
end
end
def edit
#subject = Subject.find(params[:id])
end
def update
#subject = Subject.find(params[:id])
if #subject.update_attributes(subject_params)
flash[:notice] = "Subject Updated Successfully"
redirect_to(:action => 'show')
else
render('edit')
end
end
def delete
#subject = Subject.find(params[:id])
end
def destroy
#subject = Subject.find(params[:id])
#subject.destroy
flash[:notice] = "Subject Destroyed Successfully"
redirect_to(:action => "index")
end
private
def subject_params
params.require(:subject).permit(:name, :position, :visible)
end
end
edit.html.erb
<%= link_to("<< Back to List", {:action => 'show'}, :class => 'back-link') %>
<div>
<h2>Update Subjects</h2>
<%= form_for(:subject, :url => {:action => "update", :id => #subject.id}) do |f| %>
<table summary="Subject form field">
<tr>
<th>Name</th>
<td><%= f.text_field(:name) %></td>
</tr>
<tr>
<th>Position</th>
<td><%= f.text_field(:position) %></td>
</tr>
<tr>
<th>Visbile</th>
<td><%= f.text_field(:visible) %></td>
</tr>
</table>
<div class="form-buttons">
<%= f.submit("Update Subject") %>
</div>
<% end %>
</div>
rake routes
$ rake routes
Prefix Verb URI Pattern Controller#Action
sections GET /sections(.:format) sections#index
POST /sections(.:format) sections#create
new_section GET /sections/new(.:format) sections#new
edit_section GET /sections/:id/edit(.:format) sections#edit
section GET /sections/:id(.:format) sections#show
PATCH /sections/:id(.:format) sections#update
PUT /sections/:id(.:format) sections#update
DELETE /sections/:id(.:format) sections#destroy
pages GET /pages(.:format) pages#index
POST /pages(.:format) pages#create
new_page GET /pages/new(.:format) pages#new
edit_page GET /pages/:id/edit(.:format) pages#edit
page GET /pages/:id(.:format) pages#show
PATCH /pages/:id(.:format) pages#update
PUT /pages/:id(.:format) pages#update
DELETE /pages/:id(.:format) pages#destroy
subjects GET /subjects(.:format) subjects#index
POST /subjects(.:format) subjects#create
new_subject GET /subjects/new(.:format) subjects#new
edit_subject GET /subjects/:id/edit(.:format) subjects#edit
subject GET /subjects/:id(.:format) subjects#show
PATCH /subjects/:id(.:format) subjects#update
PUT /subjects/:id(.:format) subjects#update
DELETE /subjects/:id(.:format) subjects#destroy
No need to specify match ':controller(/:action(/id))', :via => [:get, :post] in the routes. resources :subjects will give u route for all new, create, update, show & delete actions. Try this
Rails.application.routes.draw do
resources :subjects
end
As pulkit21 already stated, you don't need that match in your routes. That works for some specific cases, but in general this is usually hacky code that can be avoided with the correct usage of resource routing.
Removing that line in your routes file will then give you the error "No route matches [POST] "/subjects/1". While I don't fully understand why this happens, I do know that the form_for helper don't need to have the :url parameter set. As a matter of fact, when you use the rails scaffold to generate a controller and views, it uses a single form on a partial file for both the new and edit pages. It can do that because it can detect if a object is a new record (don't have an ID yet, so call CREATE) or is an existing record (already has a database ID, so call PUT to update).
In your case, Rails seems to be misunderstanding the :action => "update" part and instead of routing this to the PUT method (which will call the update method on your controller), is routing it to POST.
Try changing your form_for to this:
<%= form_for(#subject) do |f| %>
It's more elegant, readable and simple, and has the advantage of being able to work for both new and edit forms.
Controller:
def index
#assets = current_customer.assets
end
def destroy
#asset = current_customer.assets.find_by(id: params[:id])
redirect_to root_url
end
Index.html.erb:
<% for asset in #assets %>
<% assetcount += 1 %>
<%= image_tag asset.file_name.url(:thumb).to_s %>
<ul id="hover<%= assetcount %>" class="assets-dropdown text-center" data-dropdown-content>
<li>Source Image</li>
<li><%= link_to "Delete Image", asset, method: :delete %></li>
</ul>
<% end %>
Routes:
resources :customers do
resources :assets
end
When I click on my Delete Image link_to I get a Routing Error: No route matches [DELETE] "/"
My routes:
home_index_path GET /home/index(.:format) home#index
root_path GET / home#index
customer_assets_path GET /customers/:customer_id/assets(.:format) assets#index
POST /customers/:customer_id/assets(.:format) assets#create
new_customer_asset_path GET /customers/:customer_id/assets/new(.:format) assets#new
edit_customer_asset_path GET /customers/:customer_id/assets/:id/edit(.:format) assets#edit
customer_asset_path GET /customers/:customer_id/assets/:id(.:format) assets#show
PATCH /customers/:customer_id/assets/:id(.:format) assets#update
PUT /customers/:customer_id/assets/:id(.:format) assets#update
DELETE /customers/:customer_id/assets/:id(.:format) assets#destroy
customers_path GET /customers(.:format) customers#index
POST /customers(.:format) customers#create
new_customer_path GET /customers/new(.:format) customers#new
edit_customer_path GET /customers/:id/edit(.:format) customers#edit
customer_path GET /customers/:id(.:format) customers#show
PATCH /customers/:id(.:format) customers#update
PUT /customers/:id(.:format) customers#update
DELETE /customers/:id(.:format) customers#destroy
sessions_path POST /sessions(.:format) sessions#create
new_session_path GET /sessions/new(.:format) sessions#new
session_path DELETE /sessions/:id(.:format) sessions#destroy
register_path GET /register(.:format) customers#new
signout_path DELETE /signout(.:format) sessions#destroy
signin_path GET /signin(.:format) sessions#new
It looks like the route is there.. DELETE /customers/:customer_id/assets/:id(.:format) assets#destroy
Anyone know why?
Your error is in this line
<%= link_to "Delete Image", asset, method: :delete %>
You want to pass the customer as well
<%= link_to "Delete Image", [current_customer, asset], method: :delete %></li>
To be more clear you might want
<%= link_to "Delete Image", path_for(current_customer, asset), method: :delete %></li>
Also, you are not actually destroying the #asset in your destroy method :)
def destroy
if asset = current_customer.assets.find_by(id: params[:id])
asset.destroy! #or destroy without ! but then it could rollback in not destroy
end
redirect_to root_url
end
<%= link_to "Delete Image", [current_customer, asset], method: :delete %>
If 'current_customer' is a helper and it is available in the view:
<%= link_to "Delete Image", [current_customer, asset], method: :delete %>
If not:
<%= link_to "Delete Image", [asset.customer, asset], method: :delete %>
You can also change your routes if you want assets not to be nested in customers when destroy:
resources :customers do
resources :assets, exept: :destroy
end
resources :assets, only: :destroy
I have built a simple Rails app that has posts with one/many comments.
I want to create a simple post view that allows me to view the post and associated comments. I want each comment to have links to - view, edit, delete.
However whenever I try amending the code below I get routing errors. Help?
routes.rb
resources :posts do
resources :comments
end
rake routes
post_comments GET /posts/:post_id/comments(.:format) comments#index
POST /posts/:post_id/comments(.:format) comments#create
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit
post_comment GET /posts/:post_id/comments/:id(.:format) comments#show
PUT /posts/:post_id/comments/:id(.:format) comments#update
DELETE /posts/:post_id/comments/:id(.:format) comments#destroy
comments_controller.rb
def show
#comment = Comment.find(params[:id])
respond_to do |format|
format.html
format.json { render :json => #post }
end
end
def edit
#comment = Comment.find(params[:id])
end
comments\show.html.erb
<p>
<b>Commenter:</b>
<%= #comment.user_id %>
</p>
<p>
<b>Comment:</b>
<%= #comment.text %>
</p>
<%= link_to 'View Comment', comment_path(?) %> |
<%= link_to 'Edit Comment', edit_comment_path(?) %> |
<%= link_to 'Delete Comment', [#post, comment],
:confirm => 'Are you sure?',
:method => :delete %></p>
Are you seeing:
Routing Error
No route matches {:action=>"show", :controller=>"comments"}
Try running rake routes for more information on available routes.
I duplicated your project with the code you provided and only received that routing error because there wasn't an id being passed to the route helper methods. Because these are restful routes, the format for View Comment should be /comments/:id(.:format).
I was able to resolve this error by passing an id or comment object to the comment_path and edit_comment_path helper methods like so:
<%= link_to 'View Comment', comment_path(2) %> |
<%= link_to 'Edit Comment', edit_comment_path(3) %> |
<%= link_to 'Delete Comment', [#post, comment],
:confirm => 'Are you sure?',
:method => :delete %></p>
Obviously you would want to populate them with the correct ids or comment objects rather than just some random id.
Hope this helps.
Cheers!
I got it!
= link_to 'Zurück', page_path
That doesn't work in a new page. The page hasn't yet been created, so I can not go back to it...
This sure works fine in "edit", where the page exists
A good reason to spend the effort to get rspec to run :-)
Anyway, thank for the comments!
I got a little further....
The routing seems to work. But my form seems to be the problem?!
This is my view/pages/new.html.haml
= render 'form'
and it gets rendered if I do this:
%p I should be a form for the new page...
=# render 'form'
So it seems to be a problem with my _form.html.haml - which works fine for "edit"
= javascript_include_tag "#{root_url}javascripts/tiny_mce_head.js"
= form_for #page do |f|
-if #page.errors.any?
#error_explanation
%h2= "#{pluralize(#page.errors.count, "error")} prohibited this page from being saved:"
%ul
- #page.errors.full_messages.each do |msg|
%li= msg
.field
= f.text_area( :content, :class => 'mce_editor')
.field
= f.label :fan_only
= f.check_box :fan_only
.field
= f.label :short_name
%br
= f.text_field :short_name
.field
= f.label :title
%br
= f.text_field :title
.actions
= f.submit 'Save'
= link_to 'Zurück', page_path
Any ideas???
I've already tried without the javascript_include_tag
original post
I can't create a new page anymore. It was working and I have no idea why it doesn't anymore!
If I browse to http://localhost:3000/pages/new
I get the following message:
No route matches {:action=>"show", :controller=>"pages"}
These are my routes
scope '/my-scope' do
resources :pages do
resources :articles
end
end
root :to => 'pages#index'
rake routes
page_articles GET /my-scope/pages/:page_id/articles(.:format) {:action=>"index", :controller=>"articles"}
POST /my-scope/pages/:page_id/articles(.:format) {:action=>"create", :controller=>"articles"}
new_page_article GET /my-scope/pages/:page_id/articles/new(.:format) {:action=>"new", :controller=>"articles"}
edit_page_article GET /my-scope/pages/:page_id/articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
page_article GET /my-scope/pages/:page_id/articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /my-scope/pages/:page_id/articles/:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /my-scope/pages/:page_id/articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}
pages GET /my-scope/pages(.:format) {:action=>"index", :controller=>"pages"}
POST /my-scope/pages(.:format) {:action=>"create", :controller=>"pages"}
new_page GET /my-scope/pages/new(.:format) {:action=>"new", :controller=>"pages"}
edit_page GET /my-scope/pages/:id/edit(.:format) {:action=>"edit", :controller=>"pages"}
page GET /my-scope/pages/:id(.:format) {:action=>"show", :controller=>"pages"}
PUT /my-scope/pages/:id(.:format) {:action=>"update", :controller=>"pages"}
DELETE /my-scope/pages/:id(.:format) {:action=>"destroy", :controller=>"pages"}
root / {:controller=>"pages", :action=>"index"}
controllers/pages_controller.rb methodes show and new
# GET /pages/1
# GET /pages/1.json
def show
#page = Page.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: #page }
end
end
# GET /pages/new
# GET /pages/new.json
def new
#page = Page.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: #page }
end
end
This is my view/pages.html.haml
%p#notice= notice
%content.viewmode
= raw parse_content #page.content
-#if admin?
= link_to 'Edit page', edit_page_path(#page)
= link_to 'New page', new_page_path
= link_to 'Destroy page', #page, :confirm => 'Are you sure to delete page #{#page.title}?', :method => :delete
= link_to 'New article', new_page_article_path(#page)
-if #page.articles.empty?
/
= "No articles for page #{#page.short_name}"
- else
%ul.article_list
= show_articles
I'd be glad if anyone could just give me a few ideas where to start searching.
I tried but I don't get any further.
You're using scopes, so your url should be http://localhost:3000/my-scope/pages/new