Routing Error - Rails 3 - ruby-on-rails

I am getting the following error on my app when I try to access /messages/new:
No route matches [GET] "/messages/new"
If I try adding a /messages/new route to config.rb, I get the following error:
No route matches {:controller=>"messages"}
The app itself is like Gumtree.com, where Users come and create Posts (e.g. selling my car), and people respond my sending them Messages (through the Simple Pvt Messages plugin).
Any insights on this would be greatly appreciated.
Thanks!
Faisal
ROUTES.RB
Mysalary::Application.routes.draw do
resources :users do
resources :messages do
collection do
post :delete_selected
end
end
end
resources :users
resources :profiles
resources :pages
resources :posts
resources :messages
get "pages/home"
get "pages/about"
get "pages/legal"
get "pages/feedback"
root :to => 'posts#new'
end
MESSAGE>NEW VIEW
<% form_for #message, :url => user_messages_path(#user) do |f| %>
<p>
To:<br />
<%= f.text_field :to %>
<%= error_message_on #message, :to %>
</p>
<p>
Subject:<br />
<%= f.text_field :subject %>
<%= error_message_on #message, :subject %>
</p>
<p>
Message<br />
<%= f.text_area :body %>
<%= error_message_on #message, :body %>
</p>
<p>
<%= submit_tag "Send" %>
</p>
<% end %>
MESSAGES CONTROLLER
class MessagesController < ApplicationController
before_filter :set_user
def index
if params[:mailbox] == "sent"
#messages = #user.sent_messages
else
#messages = #user.received_messages
end
end
def show
#message = Message.read_message(params[:id], current_user)
end
def new
#message = Message.new
if params[:reply_to]
#reply_to = #user.received_messages.find(params[:reply_to])
unless #reply_to.nil?
#message.to = #reply_to.sender.login
#message.subject = "Re: #{#reply_to.subject}"
#message.body = "\n\n*Original message*\n\n #{#reply_to.body}"
end
end
end
def create
#message = Message.new(params[:message])
#message.sender = #user
#message.recipient = User.find_by_login(params[:message][:to])
if #message.save
flash[:notice] = "Message sent"
redirect_to user_messages_path(#user)
else
render :action => :new
end
end
def delete_selected
if request.post?
if params[:delete]
params[:delete].each { |id|
#message = Message.find(:first, :conditions => ["messages.id = ? AND (sender_id = ? OR recipient_id = ?)", id, #user, #user])
#message.mark_deleted(#user) unless #message.nil?
}
flash[:notice] = "Messages deleted"
end
redirect_to :back
end
end
private
def set_user
#user = User.first
end
end
MESSAGE MODEL
class Message < ActiveRecord::Base
is_private_message
attr_accessor :to
end
RAKE ROUTES OUTPUT
delete_selected_user_messages POST /users/:user_id/messages/delete_selected(.:format) {:action=>"delete_selected", :controller=>"messages"}
user_messages GET /users/:user_id/messages(.:format) {:action=>"index", :controller=>"messages"}
POST /users/:user_id/messages(.:format) {:action=>"create", :controller=>"messages"}
new_user_message GET /users/:user_id/messages/new(.:format) {:action=>"new", :controller=>"messages"}
edit_user_message GET /users/:user_id/messages/:id/edit(.:format) {:action=>"edit", :controller=>"messages"}
user_message GET /users/:user_id/messages/:id(.:format) {:action=>"show", :controller=>"messages"}
PUT /users/:user_id/messages/:id(.:format) {:action=>"update", :controller=>"messages"}
DELETE /users/:user_id/messages/:id(.:format) {:action=>"destroy", :controller=>"messages"}
messages GET /messages(.:format) {:action=>"index", :controller=>"messages"}
POST /messages(.:format) {:action=>"create", :controller=>"messages"}
new_message GET /messages/new(.:format) {:action=>"new", :controller=>"messages"}
edit_message GET /messages/:id/edit(.:format) {:action=>"edit", :controller=>"messages"}
message GET /messages/:id(.:format) {:action=>"show", :controller=>"messages"}
PUT /messages/:id(.:format) {:action=>"update", :controller=>"messages"}
DELETE /messages/:id(.:format) {:action=>"destroy", :controller=>"messages"}
pages_home GET /pages/home(.:format) {:action=>"home", :controller=>"pages"}
pages_about GET /pages/about(.:format) {:action=>"about", :controller=>"pages"}
pages_legal GET /pages/legal(.:format) {:action=>"legal", :controller=>"pages"}
pages_feedback GET /pages/feedback(.:format) {:action=>"feedback", :controller=>"pages"}
messages_new GET /messages/new(.:format) {:action=>"new", :controller=>"messages"}
root

Replace your route file with this you are defining resource message inside users and also twice.
Mysalary::Application.routes.draw do
resources :messages do
collection do
post :delete_selected
end
end
resources :users
resources :profiles
resources :pages
resources :posts
get "pages/home"
get "pages/about"
get "pages/legal"
get "pages/feedback"
root :to => 'posts#new'
end
Try it...

Related

No route matches [POST] "parent/id/child/new" error on nested association

Companies has_many Quotes, trying to create a new Quote in the Quotes controller, nested routes in place, yet i get a;
No route matches [POST] "/companies/123/quotes/new"
routes.rb
resources :companies do
resources :quotes, only: [ :new, :create, :show, :index]
resources :employees, only: [:show, :index]
end
rake routes
Prefix Verb URI Pattern Controller#Action
company_quotes GET /companies/:company_id/quotes(.:format) quotes#index
POST /companies/:company_id/quotes(.:format) quotes#create
new_company_quote GET /companies/:company_id/quotes/new(.:format) quotes#new
company_quote GET /companies/:company_id/quotes/:id(.:format) quotes#show
company_employees GET /companies/:company_id/employees(.:format) employees#index
company_employee GET /companies/:company_id/employees/:id(.:format) employees#show
companies GET /companies(.:format) companies#index
POST /companies(.:format) companies#create
new_company GET /companies/new(.:format) companies#new
edit_company GET /companies/:id/edit(.:format) companies#edit
company GET /companies/:id(.:format) companies#show
PATCH /companies/:id(.:format) companies#update
PUT /companies/:id(.:format) companies#update
DELETE /companies/:id(.:format) companies#destroy
root GET / companies#new
new.html.erb
<div class='form-group col-md-6 quote-form'>
<%= simple_form_for [#company, #quote] do |quote| %>
<%= render 'quote_fields', :f => quote %>
<%= quote.submit "Get Quote", class: 'btn btn-primary' %>
<% end %>
</div>
_quote_fields.html.erb
<%= f.input :lives_overseas, as: :radio_buttons, collection: [['Yes', true],
['No', false]], readonly: nil %>
<%= f.input :payment_frequency, collection: Quote.payment_frequencies.map { |k,v| [ k.humanize, k ] } %>
<%= params.inspect %>
quotes_controller.rb
class QuotesController < ApplicationController
before_action :authenticate_user!, only: [ :new, :create, :show, :index ]
def new
#company = Company.find(params[:company_id])
#quote = #company.quotes.build
end
def create
#company = Company.find(params[:company_id])
#quote = #company.quotes.build(params[:quote])
if #quote.save
render 'show'
end
end
def show
#company = Company.find(params[:company_id])
#quote = #company.quotes.find(params[:id])
#employees = #company.employees.all
# puts debug(params)
end
def index
#company = Company.find(params[:company_id])
#quotes = #company.quotes.all
#employees = #company.employees.all
end
end
Shouldn't the submit action on the quote form be posting to; POST /companies/:company_id/quotes(.:format), which is clearly present from rake routes?
Any ideas what I'm doing wrong here? Thanks for the guidance.
No route matches [POST] "/companies/123/quotes/new"
You are having nested resources, so you need to change
<%= simple_form_for #quote do |quote| %>
to
<%= simple_form_for [#comapny,#quote] do |quote| %>
And change #quote = #company.quotes.build to just #quote = Quote.new in quotes#new method

Routing Error uninitialized constant Comments – Making Nested comments

I'm learning Rails. I've got an app that has "Ideas", which have "Comments"
I've created the comments using this guide (https://gorails.com/episodes/comments-with-polymorphic-associations)
I am using the 'Ancestry' gem to attempt make them nested using this guide on railscasts (http://railscasts.com/episodes/262-trees-with-ancestry)
Anyways I'm getting this error "ActionController::RoutingError (uninitialized constant Comments):"
This is where I'm getting the error – when I hit the "Reply" link
<h3> Comments </h3>
<% #idea.comments.each do |comment| %>
<div>
<%= comment.body %>
<div class="actions">
<%= link_to "Reply", new_comment_path(:parent_id => comment) %>
</div>
</div>
<% end %>
The above is being rendered on the "Ideas/show.html" page
<p id="notice"><%= notice %></p>
<p>
<strong>Description:</strong>
<%= #idea.description %>
</p>
<%= render partial: "comments/comments", locals: {commentable: #idea} %>
<%= render partial: "comments/form", locals: {commentable: #idea} %>
<% if #idea.user == current_user %>
<%= link_to 'Edit', edit_idea_path(#idea) %>
<% end %>
<%= link_to 'Back', ideas_path %>
I want to send them here to "Comments/new" which is the same as my form page
<%= form_for [commentable, Comment.new] do |f| %>
<div class="form-group">
<%= f.hidden_field :parent_id %>
<%= f.text_area :body, class: "form-control", placeholder: "Add a comment here" %>
</div>
<%= f.submit class: "btn btn-primary" %>
<% end %>
Routes.rb
Rails.application.routes.draw do
resources :ideas do
resources :comments, module: :ideas
end
devise_for :users
root 'ideas#index'
get "about" => "pages#about"
get "new_comment" => "comments/new"
end
Comments_controller.rb
class CommentsController < ApplicationController
before_action :authenticate_user!
def new
#comment = Comment.new(:parent_id => params[:parent_id])
end
def create
#comment = #commentable.comments.new comment_params
#comment.user = current_user
#comment.save
redirect_to #commentable, notice: "Your comment was posted"
end
private
def comment_params
params.require(:comment).permit(:body)
end
end
Ideas_controller.rb
class IdeasController < ApplicationController
before_action :set_idea, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
before_action :correct_user, only: [:edit, :update, :destroy]
respond_to :html
def index
#ideas = Idea.all
end
def show
end
def new
#idea = Idea.new
#idea.comments.build
respond_with(#idea)
end
def edit
end
def create
#idea = current_user.ideas.build(idea_params)
if #idea.save
redirect_to #idea, notice: "Idea was successfully created."
else
render :action => 'new'
end
end
def update
if #idea.update(idea_params)
redirect_to #idea, notice: "Your idea has been updated"
else
render action: 'edit'
end
end
def destroy
#idea.destroy
redirect_to ideas_url
end
private
def set_idea
#idea = Idea.find(params[:id])
end
def correct_user
#idea = current_user.ideas.find_by(id: params[:id])
redirect_to ideas_path, notice: "You can't edit this" if #idea.nil?
end
def idea_params
params.require(:idea).permit(:description)
end
end
Any help would be much appreciated, thank you.
EDIT _ Added my routes
idea_comments GET /ideas/:idea_id/comments(.:format) ideas/comments#index
POST /ideas/:idea_id/comments(.:format) ideas/comments#create
new_idea_comment GET /ideas/:idea_id/comments/new(.:format) ideas/comments#new
edit_idea_comment GET /ideas/:idea_id/comments/:id/edit(.:format) ideas/comments#edit
idea_comment GET /ideas/:idea_id/comments/:id(.:format) ideas/comments#show
PATCH /ideas/:idea_id/comments/:id(.:format) ideas/comments#update
PUT /ideas/:idea_id/comments/:id(.:format) ideas/comments#update
DELETE /ideas/:idea_id/comments/:id(.:format) ideas/comments#destroy
ideas GET /ideas(.:format) ideas#index
POST /ideas(.:format) ideas#create
new_idea GET /ideas/new(.:format) ideas#new
edit_idea GET /ideas/:id/edit(.:format) ideas#edit
idea GET /ideas/:id(.:format) ideas#show
PATCH /ideas/:id(.:format) ideas#update
PUT /ideas/:id(.:format) ideas#update
DELETE /ideas/:id(.:format) ideas#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root GET / ideas#index
about GET /about(.:format) pages#about
new_comment GET /new_comment(.:format) comments/new#new_comment

Rails: Routing Error: No route matches [PATCH] "/things"

I created an edit form for my model "Things", but when I submit the form, it returns the error "No route matches [PATCH] "/things"". The weird thing is, the url of the error is http://localhost:3000/things, but I was expecting it to be http://localhost:3000/things/:id, because I wrote redirect_to #thing under the create function. I just defined all my Thing routes with resources :things, so it should have the update path defined. What am I doing wrong?
things_controller:
class ThingsController < ApplicationController
def show
#thing = Thing.find(params[:id])
#category_things = CategoryThing.all
#thing.categories.build
#thing.things.build
#related_things = RelatedThing.all
end
def index
end
def new
#thing = Thing.new
#things = Thing.all
end
def create
#thing = Thing.new(thing_params)
if #thing.save
redirect_to #thing
else
render 'new'
end
end
def edit
#thing = Thing.find(params[:id])
end
def update
#thing = Thing.find(params[:id])
if #thing.update_attributes(thing_params)
flash[:success] = "Thing updated"
redirect_to #thing
else
render 'edit'
end
end
private
def thing_params
params.require(:thing).permit(:name, :image_path, :avatar)
end
end
things/edit.html.erb:
<h1>Edit <%= #thing.name %></h1>
<p>
<%= form_for #thing, :url => things_path, :html => { :multipart => true } do |f| %>
<%= f.text_field :name, :placeholder => "Name of the thing" %>
<br>
<%= f.label :categories_the_thing_belongs_to %>
<%= f.collection_select :categories, Category.all, :id, :name %>
<br>
<%= f.label :related_things %>
<%= f.collection_select :related_things, Thing.all, :id, :name %>
<br>
<%= f.label :display_picture %>
<%= f.file_field :avatar %>
<br>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
</p>
Output of rake routes
Prefix Verb URI Pattern Controller#Action
ratings_new GET /ratings/new(.:format) ratings#new
down_votes_new GET /down_votes/new(.:format) down_votes#new
thing_new GET /thing/new(.:format) thing#new
good_comments_new GET /good_comments/new(.:format) good_comments#new
good_comments_show GET /good_comments/show(.:format) good_comments#show
bad_comments_new GET /bad_comments/new(.:format) bad_comments#new
related_things_new GET /related_things/new(.:format) related_things#new
things_new GET /things/new(.:format) things#new
category_things_new GET /category_things/new(.:format) category_things#new
thing_ratings_new GET /thing_ratings/new(.:format) thing_ratings#new
category_ratings_new GET /category_ratings/new(.:format) category_ratings#new
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
subjects_show GET /subjects/show(.:format) subjects#show
subject_things_new GET /subject_things/new(.:format) subject_things#new
categories GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category GET /categories/new(.:format) categories#new
edit_category GET /categories/:id/edit(.:format) categories#edit
category GET /categories/:id(.:format) categories#show
PATCH /categories/:id(.:format) categories#update
PUT /categories/:id(.:format) categories#update
DELETE /categories/:id(.:format) categories#destroy
categories_results GET /categories/results(.:format) categories#results
subjects_new GET /subjects/new(.:format) subjects#new
root GET / home_page#home
all_things_new GET /all/things/new(.:format) things#new
all_allthings GET /all/allthings(.:format) all#allthings
thing_good_comments GET /things/:thing_id/good_comments(.:format) good_comments#index
POST /things/:thing_id/good_comments(.:format) good_comments#create
new_thing_good_comment GET /things/:thing_id/good_comments/new(.:format) good_comments#new
edit_thing_good_comment GET /things/:thing_id/good_comments/:id/edit(.:format) good_comments#edit
thing_good_comment GET /things/:thing_id/good_comments/:id(.:format) good_comments#show
PATCH /things/:thing_id/good_comments/:id(.:format) good_comments#update
PUT /things/:thing_id/good_comments/:id(.:format) good_comments#update
DELETE /things/:thing_id/good_comments/:id(.:format) good_comments#destroy
thing_bad_comments GET /things/:thing_id/bad_comments(.:format) bad_comments#index
POST /things/:thing_id/bad_comments(.:format) bad_comments#create
new_thing_bad_comment GET /things/:thing_id/bad_comments/new(.:format) bad_comments#new
edit_thing_bad_comment GET /things/:thing_id/bad_comments/:id/edit(.:format) bad_comments#edit
thing_bad_comment GET /things/:thing_id/bad_comments/:id(.:format) bad_comments#show
PATCH /things/:thing_id/bad_comments/:id(.:format) bad_comments#update
PUT /things/:thing_id/bad_comments/:id(.:format) bad_comments#update
DELETE /things/:thing_id/bad_comments/:id(.:format) bad_comments#destroy
thing_ratings GET /things/:thing_id/ratings(.:format) ratings#index
POST /things/:thing_id/ratings(.:format) ratings#create
new_thing_rating GET /things/:thing_id/ratings/new(.:format) ratings#new
edit_thing_rating GET /things/:thing_id/ratings/:id/edit(.:format) ratings#edit
thing_rating GET /things/:thing_id/ratings/:id(.:format) ratings#show
PATCH /things/:thing_id/ratings/:id(.:format) ratings#update
PUT /things/:thing_id/ratings/:id(.:format) ratings#update
DELETE /things/:thing_id/ratings/:id(.:format) ratings#destroy
thing_up_votes GET /things/:thing_id/up_votes(.:format) up_votes#index
POST /things/:thing_id/up_votes(.:format) up_votes#create
new_thing_up_vote GET /things/:thing_id/up_votes/new(.:format) up_votes#new
edit_thing_up_vote GET /things/:thing_id/up_votes/:id/edit(.:format) up_votes#edit
thing_up_vote GET /things/:thing_id/up_votes/:id(.:format) up_votes#show
PATCH /things/:thing_id/up_votes/:id(.:format) up_votes#update
PUT /things/:thing_id/up_votes/:id(.:format) up_votes#update
DELETE /things/:thing_id/up_votes/:id(.:format) up_votes#destroy
things GET /things(.:format) things#index
POST /things(.:format) things#create
new_thing GET /things/new(.:format) things#new
edit_thing GET /things/:id/edit(.:format) things#edit
thing GET /things/:id(.:format) things#show
PATCH /things/:id(.:format) things#update
PUT /things/:id(.:format) things#update
DELETE /things/:id(.:format) things#destroy
things_show GET /things/show(.:format) things#show
things_results GET /things/results(.:format) things#results
things_random GET /things/random(.:format) things#random
web_console /console WebConsole::Engine
Routes for WebConsole::Engine:
root GET / web_console/console_sessions#index
input_console_session PUT /console_sessions/:id/input(.:format) web_console/console_sessions#input
pending_output_console_session GET /console_sessions/:id/pending_output(.:format) web_console/console_sessions#pending_output
configuration_console_session PUT /console_sessions/:id/configuration(.:format) web_console/console_sessions#configuration
console_sessions GET /console_sessions(.:format) web_console/console_sessions#index
POST /console_sessions(.:format) web_console/console_sessions#create
new_console_session GET /console_sessions/new(.:format) web_console/console_sessions#new
edit_console_session GET /console_sessions/:id/edit(.:format) web_console/console_sessions#edit
console_session GET /console_sessions/:id(.:format) web_console/console_sessions#show
PATCH /console_sessions/:id(.:format) web_console/console_sessions#update
PUT /console_sessions/:id(.:format) web_console/console_sessions#update
DELETE /console_sessions/:id(.:format) web_console/console_sessions#destroy
just remove the :url => things_path and use:
<%= form_for #thing, :html => { :multipart => true } do |f| %>
The form_for helper automatically generates the proper resfull endpoint if using ressourcefull routes.
Depending on #thing being persisted? or a new_record? it the endpoint will be :create or :update

Rails routing error: No route matches [GET] "/conversations/'id'/reply"

I'm having trouble replying to conversations with the Mailboxer gem in Rails 4. There isn't a whole lot of documentation on this gem, or maybe I'm just not experienced enough, but I've been stuck on this for a while now.
view/conversations/index:
(shows list of all current user's conversations)
<% #conversations.each do |conversation| %>
<%= link_to conversation.subject, reply_conversation_path(conversation.id) %>
<%= conversation.updated_at.strftime("%a, %m/%e/%Y %I:%M %p") %>
<%= link_to "Move to Trash", {:controller => "conversations", :action =>
"trash", :id => conversation.id}, :title=> "Move to Trash", :method=>'post' %>
<% end %>
When I click the first link_to in the above view, I receive the routing error: No route matches [GET] "/conversations/68/reply".
I was hoping to have it render the following view, and have the correct conversation passed to it:
view/messages/_form/
(used to reply to existing conversations)
Reply:
<%= form_for :message, url: [:reply, conversation] do |f| %>
<%= f.text_area :body %>
<%= f.submit "Send Message", class: 'btn btn-primary' %>
<%= submit_tag 'Clear Reply Box', type: :reset, class: 'btn btn-danger' %>
<% end %>
Routes:
resources :users
root to: 'profiles#index'
resources :messages do
member do
post :new
end
end
resources :conversations do
member do
post :reply
post :trash
post :untrash
end
collection do
get :trashbin
post :empty_trash
end
end
Conversations Controller:
class ConversationsController < ApplicationController
before_filter :authenticate_user!
helper_method :mailbox, :conversation
def index
#conversations ||= current_user.mailbox.inbox.all
end
def reply
current_user.reply_to_conversation(conversation, *message_params(:body, :subject))
redirect_to conversation
end
def trashbin
#trash ||= current_user.mailbox.trash.all
end
def trash
conversation.move_to_trash(current_user)
redirect_to :conversations
end
def untrash
conversation.untrash(current_user)
redirect_to :back
end
def empty_trash
current_user.mailbox.trash.each do |conversation|
conversation.receipts_for(current_user).update_all(:deleted => true)
end
redirect_to :conversations
end
private
def mailbox
#mailbox ||= current_user.mailbox
end
def conversation
#conversation ||= mailbox.conversations.find(params[:id])
end
def conversation_params(*keys)
fetch_params(:conversation, *keys)
end
def message_params(*keys)
fetch_params(:message, *keys)
end
def fetch_params(key, *subkeys)
params[key].instance_eval do
case subkeys.size
when 0 then self
when 1 then self[subkeys.first]
else subkeys.map{|k| self[k] }
end
end
end
end
Messages Controller:
class MessagesController < ApplicationController
# GET /message/new
def new
#request = Request.find(params[:request])
#message = current_user.messages.new
#user = #request.user
end
# POST /message/create
def create
#user = User.find(params[:user])
#body = params[:body]
#subject = params[:subject]
current_user.send_message(#user, params[:body], params[:subject])
flash[:notice] = "Message has been sent!"
redirect_to :conversations
end
end
relevant rake routes:
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root GET / profiles#index
message POST /messages/:id(.:format) messages#new
messages GET /messages(.:format) messages#index
POST /messages(.:format) messages#create
new_message GET /messages/new(.:format) messages#new
edit_message GET /messages/:id/edit(.:format) messages#edit
GET /messages/:id(.:format) messages#show
PATCH /messages/:id(.:format) messages#update
PUT /messages/:id(.:format) messages#update
DELETE /messages/:id(.:format) messages#destroy
reply_conversation POST /conversations/:id/reply(.:format) conversations#reply
trash_conversation POST /conversations/:id/trash(.:format) conversations#trash
untrash_conversation POST /conversations/:id/untrash(.:format) conversations#untrash
trashbin_conversations GET /conversations/trashbin(.:format) conversations#trashbin
empty_trash_conversations POST /conversations/empty_trash(.:format) conversations#empty_trash
conversations GET /conversations(.:format) conversations#index
POST /conversations(.:format) conversations#create
new_conversation GET /conversations/new(.:format) conversations#new
edit_conversation GET /conversations/:id/edit(.:format) conversations#edit
conversation GET /conversations/:id(.:format) conversations#show
PATCH /conversations/:id(.:format) conversations#update
PUT /conversations/:id(.:format) conversations#update
DELETE /conversations/:id(.:format) conversations#destroy
I've been following this tutorial: http://jamestansley.com/2014/02/22/customizing-the-mailboxer-ruby-gem-2/
In case I've left anything out, here's my github repo:
https://github.com/portOdin/GoFavorIt-Heroku/tree/stackflow/app.
The route is a post route:
resources :conversations do
member do
post :reply
Your form needs to use an HTTP POST request, and because you haven't specified a method, it's defaulting to a GET request.
Replace this...
<%= form_for :message, url: [:reply, conversation] do |f| %>
with this:
<%= form_for :message, url: [:reply, conversation], method: :post do |f| %>
Your rake routes shows reply_conversation POST /conversations/:id/reply(.:format) conversations#reply but your link_to will send a get request. You need to change your route to make it a get request.

localhost:3000/my-scope/pages/new throws No route matches {:action=>"show", :controller=>"pages"}

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

Resources