ruby-on-rails - 渲染页面并传递参数

标签 ruby-on-rails ruby

我有三个 html 页面。

  • 第一页,我查看了数据列表。
  • 第二页,我查看了列表中特定元素的数据。
  • 第三页中,用户可以编辑列表中特定元素的数据。

当用户提交“表单”时,如何在第二页重定向用户?我这样试过:

render :action => "show_details",:id=>params[:id]

它有效。链接是正确的。但是不刷新页面是打不开的。

更新一

我在报告 Controller 的这个 Action 中编写我的代码:

 def setFixed
    rs=Report.find(params[:id])
    rs.state ="1"
    rs.save
    render :action => "show_details",:id=>params[:id]
  end

更新二 报告 Controller 代码:

class ReportsController < ApplicationController

  before_filter :authenticate_user, :only => [:index,:show,:show_details,:new]

  def stateDialog
    render :stateDialog, :current_state=>params[:current_state]
  end

  def setFixed
    rs=Report.find(params[:id])
    rs.state ="1"
    rs.save
    render :action=>"show_details",:id=>params[:id]
  end

  def setNotFixed
    rs=Report.find(params[:id])
    rs.state ="0"
    rs.save
    render :action=>"show_details",:id=>params[:id]
  end

  def edit
    @report=Report.find(params[:id])
  end

  def update
    @report = Report.find(params[:id])
      if @report.update_attributes(params[:report])
        flash[:notice]=''
        render :action=>"show_details",:id=>params[:id]
      else
        flash[:notice]=''
        render :action=>"show_details",:id=>params[:id]
      end
  end

  def deleteDialog
    render "deleteDialog"
  end

  def focus_maps
    render "focus_maps"
  end

  def delete
    Report.find(params[:id]).destroy
    render "show"
  end

  def index
    @report=Report.new
  end

  def logged
    render "new"
  end

  def show
    render params[:page]
  end

  def new
    @report=Report.new
  end

  def show_details
    render "show_details"
  end


  def create
    @report=Report.new( params[:report] )

    if @report.save
       flash[:notice]='Segnalazione avvenuta!'
    else
       flash[:notice]='Impossibile sottoporre la segnalazione!'
    end

    render "show"

  end
end

最佳答案

我发现必须在 render 调用之前填充参数的建议,如下所示:

@id = params[:id]
render :action => 'show_details'

这个解决方案对我有用,试试吧

关于ruby-on-rails - 渲染页面并传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17542616/

相关文章:

ruby-on-rails - 如何使用 has_and_belongs_to_many 将新模型与现有模型相关联

ruby-on-rails - 尝试打开 .gitignore 以在文本编辑器中对其进行编辑,但在 OS X Mountain Lion 上找不到文件位置

ruby-on-rails - 在 Rails 中,Rspec 给出了无效的 css 错误,但该应用程序运行正常。如何解决这个问题?

ruby - Prolog(嗯,rubylog)中的一个简单的同义词匹配器

ruby - 为什么有七个对象的新散列比六个长度的散列慢得多?

MySQL - 根据周/月数字获取 sum()

ruby-on-rails - 如何在 Rails 中传递禁用的文本框值?

ruby-on-rails - 在 Rails 表单中,如何创建 <button>

ruby-on-rails - 我无法在 Arch Linux x64 中安装 therubyracer

ruby - 在 ruby​​ 中隐藏模块方法的最佳方法是什么?