-3

When I open http://localhost:3000/users I'm getting following routing error:

No route matches {:action=>"req", :controller=>"friendship", :id=>"admin@ascratech.com"}

How to solve this?

Inside users/index.html.erb :

<ul>
  <% @users.each do |user| %>
  <li>
    <%= user.full_name %>
    (<%= link_to "request friendship",
              :controller => :friendships,
              :action => :req,
              :id => user.email %>)  
    </li>
  <% end %>
</ul>

Inside FriendshipsController:

def req
    @user = User.logged_in(session)
    @friend = User.find_by_email(params[:id])
    unless @friend.nil?
      if Friendship.request(@user, @friend)
        flash[:notice] = "Friendship with #{@friend.full_name} requested"
      else
        flash[:notice] = "Friendship with #{@friend.full_name} cannot be requested"
      end
    end

    redirect_to :controller => :users, :action => :index
  end

Inside routes.rb:

resources :friendships
Nikita
  • 9
  • 5
  • i am trying to create friendship model.when i open http://localhost:3000/users it should show all the registered users and request friendship link in front of them.on clicking requst friendship it should go to friendships controllers req action.but i am getting error on index.html.erb file of users on clicking http://localhost:3000/users – Nikita Mar 12 '12 at 07:50
  • What's the point with the "feedbacks" resource ? You're using a non RESTful action (`friendships#req`), your routes.rb should define some sort of routes to handle your requests to the friendhsips controller : `get 'friendships/:id' => 'friendships#req'`. – Jef Mar 12 '12 at 08:06
  • @ jef "feedbacks" resource wrote it mistakenly..its resources :friendships. – Nikita Mar 12 '12 at 08:35

2 Answers2

0

Maybe you want do:

resources :friendships do
  member do
    get :req
  end
end
Peter DeWeese
  • 17,664
  • 8
  • 75
  • 98
shingara
  • 44,790
  • 11
  • 96
  • 104
0

It think... The way this is set up, Rails will be trying to fetch the resource /friendship/req/id where it will expect id to tell it if you want the 1st, 3rd, or 22nd req.

But you have given it :id=>"admin@ascratech.com" Rails is looking for a number, and you've given it a string.

Ed Jones
  • 633
  • 1
  • 4
  • 18