No route matches

Hey everyone,

I have to define a new function(called it “send”) in my
controller(newsletter_controller.rb). In the routes.rb I added the
following line
match ‘newsletters/send’ => ‘newsletters#show’, :as => :send

and in the html.erb I try to use the action send by:
<%= link_to ‘Send Newsletter’, :action => :send %>

Everything is in the same controller(newsletters) however the error
occures No route matches {:action=>“send”, :controller=>“newsletters”}

Do I have to tell Rails that there is a new function in the controller?
Because it looks like Rails just can’t find the function send…
Is the match correct? I’m not really sure about the syntax of it and
which element means what…

Thanks for help!

match ‘newsletters/send’ => ‘newsletters#show’, :as => :send

this makes no sense, if you have resources :newsletters declared and you
are
pointing at the show action witch has this form

newsletters/:id

and then you are not passing an id, it is correctly says that no route
matches since the show action needs an id.

What is that you are trying to achieve? because you appear to be wanting
to
point to a send action in the controller but then you make
match point at the show action with this

‘newsletters#show’

In my controller in the function send is a method to send Newsletters
via email. In show.html.erb the newsletter is shown to the administrator
who is able to send it, by clicking on a button “Send Newsletter”.

What is that you are trying to achieve? because you appear to be wanting
to point to a send action in the controller

I thought it would be nice to see the Newsletter again after it was
sent.
I hope this answers your questions.

Thx

On Thu, Dec 9, 2010 at 11:48 AM, Susanne P. [email protected]
wrote:

kind of does. first if you want to point to an action you should do

resources :newsletters do
get ‘send’, :on => :member
end

if the controller is restful it should be

this will create something like

newsletters/:id/send

in the controller inside the send action redirect to the show action at
the
end to show the news letter

On 9 December 2010 14:54, Susanne P. [email protected] wrote:

Hey everyone,

I have to define a new function(called it “send”) in my
controller(newsletter_controller.rb).

Everything is in the same controller(newsletters) however the error
occures No route matches {:action=>“send”, :controller=>“newsletters”}

You may run into problems because “send” is a reserved word:
http://wiki.rubyonrails.org/rails/pages/reservedwords

I’d change the name of the action, and try again to see what occurs.

Marnen Laibow-Koser wrote in post #967458:

Does the send method exist yet?

Yes, it exists.

Thanks for the answeres. I’ll try it.

Michael, this sounds logical. Forgot about that issue.

Susanne P. wrote in post #967430:

Hey everyone,

I have to define a new function(called it “send”) in my
controller(newsletter_controller.rb). In the routes.rb I added the
following line
match ‘newsletters/send’ => ‘newsletters#show’, :as => :send

and in the html.erb I try to use the action send by:
<%= link_to ‘Send Newsletter’, :action => :send %>

Everything is in the same controller(newsletters) however the error
occures No route matches {:action=>“send”, :controller=>“newsletters”}

Do I have to tell Rails that there is a new function in the controller?
Because it looks like Rails just can’t find the function send…

Does the send method exist yet?

Is the match correct? I’m not really sure about the syntax of it and
which element means what…

http://railsapi.com/doc/rails-v3.0.1/classes/ActionDispatch/Routing.html

Thanks for help!

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

It works!

I added this in the routes.rb

resources :newsletters do
get ‘send’, :on => :member
end

and in the controller I redirected to the page where the newsletters are
shown…

Thanks a lot everyone!

Just to be clear. Having action named “send” in a controller is a very
bad idea. “send” is a method available for every ruby object and it is
quite important method. It is not a good idea to overwrite it. I would
name it “deliver”.

Robert Pankowecki