简体   繁体   English

将数据从HTML传递到Rails上的控制器ruby

[英]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------------ 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 的routes.rb

post 'wendy', to: 'blog#wendy  

Controller------------------------------ 控制器------------------------------

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

try this: after selecting course you will get can find that course at controller side and storing it in @gg variable HTML........... 试试看:选择课程后,您将可以在控制器端找到该课程并将其存储在@gg变量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

我解决了,我必须从SQL查询中获取@cursitos的ID

@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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM