Rosalba Lancheros
Rosalba Lancheros

Reputation: 1

pass data from html to controller ruby on rails

Hi i want to send the selected object to a controller method but I dont know how. this is the select list with the vaules in it

Html------------

<%= form_tag '/wendy' do %>
  <%= select_tag :'buenwendy', options_from_collection_for_select(@cursitos, 'id', 'name') %>
  <%= submit_tag 'buscar', class: 'btn btn-success' %>
<% end %>

routes.rb

post 'wendy', to: 'blog#wendy  

Controller------------------------------

def wendy
  gg= params[:buenwendy]
  flash[:success]= gg
  redirect_to root_path
end   

Upvotes: 0

Views: 297

Answers (2)

Rosalba Lancheros
Rosalba Lancheros

Reputation: 1

I solved it guys, I had to get the id of @cursitos from the SQL query

@cursitos = Course.find_by_sql("SELECT *courses.id*, courses.name FROM courses, cours_sts, students WHERE courses.id = cours_sts.course_id AND students.id = cours_sts.student_id AND students.id= 1")

Upvotes: 0

Anand
Anand

Reputation: 6531

try this: after selecting course you will get can find that course at controller side and storing it in @gg variable HTML...........

<%= form_tag( '/wendy', :method => :post ) %>
  <%= select_tag :'buenwendy', options_from_collection_for_select(@cursitos, 'id', 'name') %>
  <%= submit_tag 'buscar', class: 'btn btn-success' %>
<% end %>

......routes

post '/wendy', to: 'blog#wendy

controller..........

def wendy
  @gg= Course.find(params[:buenwendy])
  flash[:success]= @gg
  redirect_to root_path
end

Upvotes: 1

Related Questions