I don't know what is up, but I was experimenting with GSUB then decided I didn't want to use it anymore so changed my link_to arguments back to:
<%= link_to root_url(@user.username), @user.username %>
Now I keep getting this error: undefined method `gsub' for nil:NilClass
and when I remove that whole line from my show file everything is fine.
or if I change it to this:
<%= link_to root_url(:user => @user.username), @user.username %>
It's like it has been confused some how and thinks I'm still using the gsub method when I'm not. I've tested or url helpers such as login, password_reset etc and they all work fine. It seems to only be doing this with root_url.
I also cloned a repo of my site from yesterday before I got this issue and guess what? Same error..
I've never been this frustrated with my programming.
Is there something I can clear? I've tried clearing everything inthe tmp folder still no luck.
routes:
Mysite::Application.routes.draw do
resources :users
resources :sessions
resources :passwords
root :to => "users#new"
match 'success' => "users#success"
match 'login' => "sessions#new"
match 'logout' => "sessions#destroy"
match 'reset_password' => "passwords#new"
match 'setup_new_password' => "passwords#edit"
match ':username' => "users#show"
end
I think you have your arguments for link_to backwards. It should be:
link_to(label, url)
The gsub
method can be triggered by something else deeper inside of Rails. When you get an error, usually you get a stack trace that helps to explain the chain of events leading up to the failure.
这应该可以解决问题,因为root_url(和root_path)没有参数:
<%= link_to @user.username, root_url %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.