浏览 665 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-04-21
使用for循环,现在的界面效果是每个movie的radio_button的form要逐个提交,
怎样修改才能做到该界面的form用一个submit一起提交
<h1>用户: <%= @user.name%></h1>
<table>
<tr>
<th>英文名:</th>
<th>中文名:</th>
<th>评分:</th>
</tr>
<% for @movie in @movies %>
<tr>
<td><%=h @movie.en_title %></td>
<td><%=h @movie.ch_title %></td>
<td><%form_tag :action => 'save_test', :id => @movie do%>
差<%= radio_button_tag :lev, '1' %>
还行<%= radio_button_tag :lev, '2' %>
推荐<%= radio_button_tag :lev, '3' %>
<%=submit_tag "提交"%>
<%end%>
</td>
</tr>
<%end %>
</table>
<%= will_paginate @movies %>
def save_test
@user = session[:user]
@movie = Movie.find(params[:id])
new_rate = params[:lev]
@rating=Rating.new(:movie=>@movie,:user=>@user,:rate=> new_rate)
@rating.save
redirect_to :action => :testmovie, :id =>@user
end
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2008-04-21
shawnccx 写道 怎样修改才能做到该界面的form用一个submit一起提交 那就做成只有一个表单的形式呗 |
|
| 返回顶楼 | |
|
时间:2008-04-21
[quote="jiyanliang"][quote="shawnccx"]
那就做成只有一个表单的形式呗 [/quote] 那样的话@movies在rhtml下该怎样展开呢?? 能不能说说具体做法 |
|
| 返回顶楼 | |
|
时间:2008-04-21
shawnccx 写道 jiyanliang 写道 shawnccx 写道 那就做成只有一个表单的形式呗 那样的话@movies在rhtml下该怎样展开呢?? 能不能说说具体做法 展开应该没有问题吧; 关键是把id传到controller就行了, 这个可以在radio_button_tag中设定。 我认为还是把movie 和 投票项 作为两个模型比较好吧! <% for vote_content in @vote_contents%> <%= radio_button_tag "vote_content_ids[]",vote_content.id%> <%= vote_content.content%> <%end%> controller部分 @vote_content = VoteContent.find(params[:vote_content_ids][0]) 希望能有用,你试试 |
|
| 返回顶楼 | |
|
时间:2008-04-21
引用 展开应该没有问题吧; 关键是把id传到controller就行了, 这个可以在radio_button_tag中设定。 我认为还是把movie 和 投票项 作为两个模型比较好吧! 我已经有了一个投票结果的model rating了么 |
|
| 返回顶楼 | |
|
时间:2008-04-22
是这个意思吗?
#psuedo code <%= form_tag %> <%= render :partial => '/path/movie', :collection => @movies %> <%= end_of_form_tag %> #in _movie.rhtml <%= movie %> |
|
| 返回顶楼 | |
|
时间:2008-08-07
做成select下拉式选项也可以吧
|
|
| 返回顶楼 | |
|
时间:2008-08-08
<% form_tag :action => "save" do %>
# Table Header
<% @movies.each do |movie| %>
<%= radio_button_tag "movie_ratings[#{movie.id}]", 1 %>
<%= radio_button_tag "movie_ratings[#{movie.id}]", 2 %>
<%= radio_button_tag "movie_ratings[#{movie.id}]", 3 %>
<% end %>
# End of table
<%= submit_tag %>
<% end %>
def save
Rating.transaction do
params[:movie_rattings].eacho do |key, value|
Rating.create!(
:movie_id => key,
:user_id => session[:user].id,
:rate => value
)
end
end
redirect_to :action => "testmovie", :id => session[:user].id
rescue
render :text => "Error Message", :layout => false, :status => 500
end
RHTML 部分我就偷工减料了,写 label 标签太麻烦。所有电影的评分放在事务中,保证同时评分的完整性 |
|
| 返回顶楼 | |





