开发者

Why I got a unknown action?

开发者 https://www.devze.com 2023-01-07 15:30 出处:网络
I have a \"manageUser\" page, the route is like that: map.manageUsers \"manageUsers\", :controller => \"users\", :action => \"manageUsers\"

I have a "manageUser" page, the route is like that:

  map.manageUsers "manageUsers", :controller => "users", :action => "manageUsers"

and, it like a index of user, but provide a ban button for admin to ban the user, so, I have something like this:

<% @users.each do |user| %>

    <td><%=h user.username %></td>

        <td><%= link_to 'Ban !', user, :confirm => 'Are you sure?', :method => :ban %></td>  

<%end%>

And the users controller have the method like this:

 def ban
    @user = User.find(params[:id])    
    @user.isBan = true               
     if @user.save
       flash[:notice] = @user.username ' is successful banned.'      
     else   
       flash[:error] = @user.usern开发者_开发技巧ame ' may have greater power than you.'      

    end 
    redirect_to manageUsers_url

  end         

But when I click the link, it show me this address:

http://localhost:3000/users/46

With this error:

Unknown action

No action responded to 46. Actions:

What happen? thank you.


Because the :method in link_to helper is to define the HTTP method to request. But not the action in your controller.

You need use url_for system

<%= link_to 'Ban !', {:controller => 'users', :action => 'ban', :user_id => user.id}, {:confirm => 'Are you sure?'} %>
0

精彩评论

暂无评论...
验证码 换一张
取 消