html - I was trying to pass a parameter from from view to another ,But I am getting a wrong output? -


what trying , print table:-

id   content             have_read    created_at     updated_at 1      xyz        xxx     qwe       0           xxxx          xxxx 2      xyz        xxx     yyy       1           xxxx          xxxx 3      xyt        xxx     xxx       0           xxxx          xxxx 

when user clicks on id , link new page . , there display details of row selected .

this html file table:-

<% @messages.each |m| %>  <% if m.to == get_user %>     <tr>     <td><font color="blue"><%= link_to m.id, show_message_path(m) %></font></td>     <td><%=m.from%></td>     <td><%=m.subject%></td>     <td><%=m.created_at%></td>   </tr>   <% end %> <% end %> 

i using " show_message_path(m)" pass selected row.

my controller :-

class messagescontroller < applicationcontroller   def new    @messages = message.all   end     def show_message    @messages = message.find_by(params[:id])   end  end 

this contents of show_message.html.erb :-

<h1><%=@messages.id%></h1> 

i noticed id printed '1' irrespective of row selected .

i have used similare method project , , worked fine there . dont went wrong.

this routes.rd file:-

rails.application.routes.draw   'messages/new'    root                'static_pages#home'      'help'    => 'static_pages#help'      'about'   => 'static_pages#about'      'contact' => 'static_pages#contact'      'signup'  => 'users#new'      'newmain'  => 'users#newmain'        'login'   => 'sessions#new'   post   'login'   => 'sessions#create'   delete 'logout'  => 'sessions#destroy'   'show_message' => 'messages#show_message'   resources :users    resources :messages end 

change

get 'show_message' => 'messages#show_message' 

to

get 'show_message/:id' => 'messages#show_message', 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -