rails rjs select method help

本文介绍了一个使用Rails的RJS技术实现的简单应用案例,该应用可以在用户输入两个文本框中的数字时实时显示这两个数字的和。文章讨论了在实现过程中遇到的问题,即如何正确获取HTMLInputElement对象的值,并提出了解决方案。
在一个页面中,有两个text field。里面可以输入数字,然后在边上显示两个texi field里面数字的和。

我的方法大概是这样的。用两个observe field,来观察text field的值,一旦改变就在页面上取得两个text field的值。加在一起之后update 结果。

用的是rjs.

view的代码是:

<%= text_field 'field', "01",:class=>'sum', :value=>0 %>
<%= text_field 'field', "02",:class=>'sum', :value=>0 %>
<div id='result'>0</div>

<%= observe_field("field_01",
:frequency => 1,
:with => "num_1",
:url => {:action =>'sum'})%>

<%= observe_field("field_02",
:frequency => 1,
:with => "num_2",
:url => {:action =>'sum'})%>


controller 代码为空

def sum
end


rjs 代码


#result = 0
page.select("input.sum").each do |ob|
# result += ob
page.alert(ob) #问题在这里
end
page.replace_html 'result', result


问题是那个在page.select 里面得到 ob 其实是个 HtmlInputElement object.
而且没有其他任何属性,也就是说得不到它的值。
ob.value就会报错。not a valid function.

其实就是计算两个数的加和。应该在用javascript就可以搞定吧。
奇怪的就是感觉用rjs也能行。但是为什么只能得到object却没有任何其他属性呢?
module KanbansHelper def kanban_contextual_menu(&block) menu = KanbanContextualMenu.new( kanban: @kanban, user: @user, view_context: self # 传递当前 Helper 实例作为视图上下文 ) concat(menu.display(capture(menu, &block))) end def name_to_css(name) name.gsub(' ','-').downcase end def jquery_dialog_div(title=:field_issue) "<div id='dialog-window' title='#{ l(title) }'></div>" end def render_pane_to_js(pane, user=nil) if Kanban.valid_panes.include?(pane) return render_to_string(:partial => pane, :locals => {:user => user }) else '' end end # Returns the CSS class for jQuery to hook into. Current users are # allowed to Drag and Drop items into their own list, but not other # people's lists def allowed_to_assign_staffed_issue_to(user) if allowed_to_manage? || User.current == user 'allowed' else '' end end def over_pane_limit?(limit, counter) if !counter.nil? && !limit.nil? && counter.to_i >= limit.to_i # 0 based counter return 'over-limit' else return '' end end # Was the last journal with a note created by someone other than the # assigned to user? def updated_note_on_issue?(issue) if issue && issue.journals.present? last_journal_with_note = issue.journals.select {|journal| journal.notes.present?}.last if last_journal_with_note && issue.assigned_to_id != last_journal_with_note.user_id last_journal_with_note else return false end end end def issue_updated_note_icon(issue) if last_journal = updated_note_on_issue?(issue) image_tag('comment.png', :class => "updated-note issue-show-popup issue-id-#{h(issue.id)}", :id => "issue-#{h(issue.id)}", :alt => l(:kanban_text_updated_issue), :title => h(last_journal.notes)) end end def kanban_issue_css_classes(issue) css = 'kanban-issue ' + issue.css_classes if User.current.logged? && !issue.assigned_to_id.nil? && issue.assigned_to_id != User.current.id css << ' assigned-to-other' end css << ' issue-behind-schedule' if issue.behind_schedule? css << ' issue-overdue' if issue.overdue? css << ' parent-issue' if issue.root? && issue.children.count > 0 css end def issue_icon_link(issue) if Setting.gravatar_enabled? && issue.assigned_to img = avatar(issue.assigned_to, { :class => 'gravatar icon-gravatar', :size => 10, :title => l(:field_assigned_to) + ": " + issue.assigned_to.name }) link_to(img, :controller => 'issues', :action => 'show', :id => issue) else link_to(image_tag('ticket.png', :style => 'float:left;'), :controller => 'issues', :action => 'show', :id => issue) end end def column_configured?(column) case column when :incoming KanbanPane::IncomingPane.configured? when :backlog KanbanPane::BacklogPane.configured? when :selected KanbanPane::QuickPane.configured? || KanbanPane::SelectedPane.configured? when :staffed true # always end end # Calculates the width of the column. Max of 96 since they need # some extra for the borders. def column_width(column) # weights of the columns column_ratios = { :incoming => 1, :backlog => 1, :selected => 1, :staffed => 4 } return 0.0 if column == :incoming && !column_configured?(:incoming) return 0.0 if column == :backlog && !column_configured?(:backlog) return 0.0 if column == :selected && !column_configured?(:selected) visible = 0 visible += column_ratios[:incoming] if column_configured?(:incoming) visible += column_ratios[:backlog] if column_configured?(:backlog) visible += column_ratios[:selected] if column_configured?(:selected) visible += column_ratios[:staffed] if column_configured?(:staffed) return ((column_ratios[column].to_f / visible) * 96).round(2) end def my_kanban_column_width(column) column_ratios = { :project => 1, :testing => 1, :active => 1, :selected => 1, :backlog => 1 } # Vertical column if column == :incoming return (KanbanPane::IncomingPane.configured? ? 100.0 : 0.0) end # Inside of Project, max width if column == :finished || column == :canceled return 100.0 end return 0.0 if column == :active && !KanbanPane::ActivePane.configured? return 0.0 if column == :testing && !KanbanPane::TestingPane.configured? return 0.0 if column == :selected && !KanbanPane::SelectedPane.configured? return 0.0 if column == :backlog && !KanbanPane::BacklogPane.configured? visible = 0 visible += column_ratios[:project] visible += column_ratios[:active] if KanbanPane::ActivePane.configured? visible += column_ratios[:testing] if KanbanPane::TestingPane.configured? visible += column_ratios[:selected] if KanbanPane::SelectedPane.configured? visible += column_ratios[:backlog] if KanbanPane::BacklogPane.configured? return ((column_ratios[column].to_f / visible) * 96).round(2) end # Calculates the width of the column. Max of 96 since they need # some extra for the borders. def staffed_column_width(column) # weights of the columns column_ratios = { :user => 1, :active => 2, :testing => 2, :finished => 2, :canceled => 2 } return 0.0 if column == :active && !KanbanPane::ActivePane.configured? return 0.0 if column == :testing && !KanbanPane::TestingPane.configured? return 0.0 if column == :finished && !KanbanPane::FinishedPane.configured? return 0.0 if column == :canceled && !KanbanPane::CanceledPane.configured? visible = 0 visible += column_ratios[:user] visible += column_ratios[:active] if KanbanPane::ActivePane.configured? visible += column_ratios[:testing] if KanbanPane::TestingPane.configured? visible += column_ratios[:finished] if KanbanPane::FinishedPane.configured? visible += column_ratios[:canceled] if KanbanPane::CanceledPane.configured? return ((column_ratios[column].to_f / visible) * 96).round(2) end def issue_url(issue) url_for(:controller => 'issues', :action => 'show', :id => issue) end def showing_current_user_kanban? @user == User.current end # Renders the title for the "Incoming" project. It can be linked as: # * New Issue jQuery dialog (user has permission to add issues) # * Link to the url configured in the plugin (plugin is configured with a url) # * No link at all def incoming_title if Setting.plugin_redmine_kanban['panes'].present? && Setting.plugin_redmine_kanban['panes']['incoming'].present? && Setting.plugin_redmine_kanban['panes']['incoming']['url'].present? href_url = Setting.plugin_redmine_kanban['panes']['incoming']['url'] incoming_project = extract_project_from_url(href_url) link_name = incoming_project.present? ? incoming_project.name : l(:kanban_text_incoming) else href_url = '' link_name = l(:kanban_text_incoming) end if User.current.allowed_to?(:add_issues, nil, :global => true) link_to(link_name, href_url, :class => 'new-issue-dialog') elsif href_url.present? link_to(link_name, href_url) else link_name end end # Given a url, extract the project record from it. # Will return nil if the url isn't a link to a project or the url can't be # recognized def extract_project_from_url(url) project = nil link_path = url. sub(request.host, ''). # Remove host sub(/https?:\/\//,''). # Protocol sub(/\?.*/,'') # Query string begin route = ActionController::Routing::Routes.recognize_path(link_path, :method => :get) if route[:controller] == 'projects' && route[:id] project = Project.find(route[:id]) end rescue ActionController::RoutingError # Parse failed, not a route end end def export_i18n_for_javascript strings = { 'kanban_text_error_saving_issue' => l(:kanban_text_error_saving_issue), 'kanban_text_issue_created_reload_to_see' => l(:kanban_text_issue_created_reload_to_see), 'kanban_text_issue_updated_reload_to_see' => l(:kanban_text_issue_updated_reload_to_see), 'kanban_text_notice_reload' => l(:kanban_text_notice_reload), 'kanban_text_watch_and_cancel_hint' => l(:kanban_text_watch_and_cancel_hint), 'kanban_text_issue_watched_reload_to_see' => l(:kanban_text_issue_watched_reload_to_see) } javascript_tag("var i18n = #{strings.to_json}") end def viewed_user return @user if @user.present? return User.current end def use_simple_issue_popup_form? # TODO: Hate how Settings is stored... @settings['simple_issue_popup_form'] && ( @settings['simple_issue_popup_form'] == '1' || @settings['simple_issue_popup_form'] == 1 || @settings['simple_issue_popup_form'] == true ) end # Load remote RJS/HTML data from url into dom_id def kanban_remote_data(url, dom_id) javascript_tag("Kanban.remoteData('#{url}', '#{dom_id}');") + content_tag(:span, l(:label_loading), :class => 'loading') end # Returns a list of pane names in the configured order. # # @param hash options Method options # @option options Array :only Filter the panes to only include these ones def ordered_panes(options={}) only = options[:only] || [] if only.present? KanbanPane.pane_order.select {|pane| only.include?(pane) } else KanbanPane.pane_order end end class UserKanbanDivHelper < BlockHelpers::Base include ERB::Util def self.parent superclass end def initialize(options={}) @column = options[:column] @user = options[:user] @project_id = options[:project_id] end def issues(issues) if issues.compact.empty? || issues.flatten.compact.empty? render :partial => 'kanbans/empty_issue' else render(:partial => 'kanbans/issue', :collection => issues.flatten, :locals => { :limit => Setting['plugin_redmine_kanban']["panes"][@column.to_s]["limit"].to_i }) end end def display(body) content_tag(:div, content_tag(:ol, body, :id => "#{@column}-issues-user-#{h(@user.id)}-project-#{h(@project_id)}", :class => "#{@column}-issues"), :id => "#{@column}-#{h(@user.id)}-project-#{h(@project_id)}", :class => "pane equal-column #{@column} user-#{h(@user.id)}", :style => "width: #{ helper.my_kanban_column_width(@column)}%") end end class KanbanContextualMenu < BlockHelpers::Base include ActionView::Helpers # 引入 Rails 视图方法 delegate :link_to, :content_tag, to: :@view_context def initialize(options={}) @view_context = options.delete(:view_context) || ActionController::Base.helpers super(options) @kanban = options[:kanban] @user = options[:user] end def color_help link_to_function(l(:kanban_text_color_help), "$('color-help').toggle();", :class => 'icon icon-info') end def kanban_board if User.current.allowed_to?(:view_kanban, nil, :global => true) link_to(l(:text_kanban_board), kanban_url, :class => 'icon icon-stats') end end def my_kanban_requests link_to(l(:text_my_kanban_requests_title), kanban_user_kanban_path(:id => User.current.id), :class => 'icon icon-user') end def assigned_requests link_to(l(:text_assigned_kanban_title), kanban_assigned_kanban_path(:id => User.current.id), :class => 'icon icon-user') end def new_issue if User.current.allowed_to?(:add_issues, nil, :global => true) if Setting.plugin_redmine_kanban['panes'].present? && Setting.plugin_redmine_kanban['panes']['incoming'].present? && Setting.plugin_redmine_kanban['panes']['incoming']['url'].present? incoming_url = Setting.plugin_redmine_kanban['panes']['incoming']['url'] incoming_project = extract_project_from_url(incoming_url) link_name = incoming_project.present? ? incoming_project.name : l(:label_issue_new) else link_name = l(:label_issue_new) end link_to_function(link_name, "void(0)", :class => 'new-issue-dialog icon icon-issue') end end def sync_kanban if User.current.allowed_to?(:edit_kanban, nil, :global => true) link_to(l(:kanban_text_sync), sync_kanban_url, :method => :put, :class => 'icon icon-reload') end end # @param [Hash] options # @option options [String] :url URL that the user switch form should post to # @option options [String] :label Text to use for the Switch User label (i18n'd already) # @option options [String] :users Users to allow switching to. Defaults to all active Users def user_switch(options={}) url = options[:url] label = options[:label] || l(:label_user_switch) users = options[:users] || User.active if kanban_settings["management_group"] && User.current.group_ids.include?(kanban_settings["management_group"].to_i) render :partial => 'kanbans/user_switch', :locals => {:url => url, :label => label, :users => users.sort} end end def display(body) content = call_hook(:view_user_kanbans_show_contextual_top, :user => @user, :kanban => @kanban).to_s content += body content += call_hook(:view_user_kanbans_show_contextual_bottom, :user => @user, :kanban => @kanban).to_s content_tag(:div, content, :class => "contextual") end end end 报错如下 ActionView::Template::Error (undefined method `kanban_contextual_menu' for #<ActionView::Base:0x0002346c0cc248>):
09-11
本设计项目聚焦于一款面向城市环保领域的移动应用开发,该应用以微信小程序为载体,结合SpringBoot后端框架与MySQL数据库系统构建。项目成果涵盖完整源代码、数据库结构文档、开题报告、毕业论文及功能演示视频。在信息化进程加速的背景下,传统数据管理模式逐步向数字化、系统化方向演进。本应用旨在通过技术手段提升垃圾分类管理工作的效率,实现对海量环保数据的快速处理与整合,从而优化管理流程,增强事务执行效能。 技术上,前端界面采用VUE框架配合layui样式库进行构建,小程序端基于uni-app框架实现跨平台兼容;后端服务选用Java语言下的SpringBoot框架搭建,数据存储则依托关系型数据库MySQL。系统为管理员提供了包括用户管理、内容分类(如环保视频、知识、新闻、垃圾信息等)、论坛维护、试题与测试管理、轮播图配置等在内的综合管理功能。普通用户可通过微信小程序完成注册登录,浏览各类环保资讯、查询垃圾归类信息,并参与在线知识问答活动。 在设计与实现层面,该应用注重界面简洁性与操作逻辑的一致性,在满足基础功能需求的同时,也考虑了数据安全性与系统稳定性的解决方案。通过模块化设计与规范化数据处理,系统不仅提升了管理工作的整体效率,也推动了信息管理的结构化与自动化水平。整体而言,本项目体现了现代软件开发技术在环保领域的实际应用,为垃圾分类的推广与管理提供了可行的技术支撑。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
内容概要:本文系统介绍了敏捷开发在汽车电子架构设计中的应用背景、核心理念及其相较于传统瀑布式开发的优势。文章从传统开发流程存在的问题切入,阐述了敏捷开发兴起的原因,并深入解析《敏捷软件开发宣言》提出的四大价值观:个体和互动高于流程和工具、工作的软件高于详尽的文档、客户合作高于合同谈判、响应变化高于遵循计划。重点强调敏捷开发以迭代为核心实践方式,通过小步快跑、持续交付可运行软件、频繁获取反馈来应对需求变化,提升开发效率与客户价值。同时展示了敏捷开发在互联网和汽车行业的广泛应用,如苹果、谷歌、博世、奔驰等企业的成功实践,证明其在智能化转型中的普适性和有效性。; 适合人群:从事汽车电子、嵌入式系统开发的工程师,以及对敏捷开发感兴趣的项目经理、产品经理和技术管理者;具备一定软件开发背景,希望提升开发效率和团队协作能力的专业人士。; 使用场景及目标:①理解敏捷开发相对于传统瀑布模型的核心优势;②掌握敏捷开发四大价值观的内涵及其在实际项目中的体现;③借鉴行业领先企业的敏捷转型经验,推动团队或组织的敏捷实践;④应用于智能汽车、车联网等快速迭代系统的开发流程优化。; 阅读建议:此资源侧重理念与实践结合,建议读者结合自身开发流程进行对照反思,在团队中推动敏捷思想的落地,注重沟通协作机制建设,并从小范围试点开始逐步实施迭代开发。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值