Saturday, 15 May 2010

ruby on rails - Can't link to another page with user -



ruby on rails - Can't link to another page with user -

i want link page user, have error:

runtimeerror in welcomecontroller#edit called id nil, mistakenly 4 -- if wanted id of nil, utilize object_id

in current page

<%= link_to "edit", welcome_edit_path(@user) %>

thi controller

def edit user = user.find_by_id(@user.id) end

in page want link to

<%= user.id %>

i know problem @user nil, dont know how link page @user so, please! help me

this routes file

"micropost/new" "user/new" "user/saved" "post/new" "post/show" "welcome/index" "welcome/sucess" "welcome/edit" root :to => "welcome#index" '/users/:id', :to => 'welcome#sucess', :as => "user" match '/relations', to: 'relation#create', via: 'post' match '/relations/:id', to: 'relation#destroy', via: 'delete' resources :users resources :relations, only: [:create, :destroy] resources :microposts match '/login', to: 'welcome#create', via: 'post' match '/logout' => 'welcome#destroy', as: :logout match '/create', to: 'micropost#create', via: 'post' match '/signup', to: 'user#signup', via: 'post'

your code in edit method makes no sense. first thing, have define route properly:

get '/welcome/edit/:id', to: 'welcome#edit', as: 'welcome_edit'

then, in welcomecontroller:

def edit @user = user.find(params[:id]) end

and link page:

<%= link_to 'edit', welcome_edit_path(@user) %>

ruby-on-rails ruby

No comments:

Post a Comment