Ruby on rails 链接到同一页?

Ruby on rails 链接到同一页?,ruby-on-rails,Ruby On Rails,我是RubyonRails新手,非常感谢您的指导 我的show.html.haml中有以下行。现在,当我点击我在show page中创建的链接时,它会加载一个指向对话消息路径的新页面。我不想加载新页面,而是想在show.html.haml页面中的某个列中看到此页面,链接_是其中的一部分。有点像偏袒 = link_to (conversation.messages.last.body),conversation_messages_path(conversation),class: "la

我是RubyonRails新手,非常感谢您的指导

我的show.html.haml中有以下行。现在,当我点击我在show page中创建的链接时,它会加载一个指向对话消息路径的新页面。我不想加载新页面,而是想在show.html.haml页面中的某个列中看到此页面,链接_是其中的一部分。有点像偏袒

= link_to (conversation.messages.last.body),conversation_messages_path(conversation),class: "last-message"

提前谢谢你。

这段代码明白你的意思吗

config/routes.rb
Rails.application.routes.draw do
  get "/home", to: "pages#home"
  root to: "pages#show"
end

app/views/pages/show.html.haml
= link_to "Message from this page. Click to go!", root_path(params.permit(:flag).merge(:flag => true))
- if @flagCount
  %form{ :action => "/save", :method => "post" }
    %fieldset
      %label{:for => "title"} This is #{@indexCount} time:
      %input{:name => "title", :type => "text", :value => ""}/
      %input{:type => "submit" }
- else
  Nothing. This is #{@indexCount} time.
%p This line is variables information: @flagCount = #{@flagCount}; @indexCount = #{@indexCount}

app/controllers/pages_controller.rb
class PagesController < ApplicationController
  # before_action :accept_all_params
  @@staticCount = 1
  @@staticFlag = false
  def home
  end

  def show
    if params[:flag].present?
      @@staticFlag = ActiveModel::Type::Boolean.new.cast(params[:flag])
      if @@staticFlag
        @@staticCount = @@staticCount + 1
      else
        @@staticCount = 1
        @@staticFlag = false
      end
    else
      @@staticCount = 1
      @@staticFlag = false
    end
    @indexCount = @@staticCount
    @flagCount = @@staticFlag
  end

  private
  # permit all parameters
  # def accept_all_params
  #   params.permit!
  # end

end
config/routes.rb
Rails.application.routes.draw do
获取“/主页”,至:“主页”
根目录为:“页面#显示”
结束
app/views/pages/show.html.haml
=链接到“来自此页面的消息。单击以转到!”,根路径(参数permit(:flag)。merge(:flag=>true))
-如果@flagCount
%格式{:action=>“/save”,:method=>“post”}
%字段集
%标签{:for=>“title”}这是{@indexCount}时间:
%输入{:name=>“title”,:type=>“text”,:value=>“”/
%输入{:type=>“提交”}
-否则
没有什么。现在是{@indexCount}时间。
%p此行是变量信息:@flagCount={@flagCount}@indexCount=#{@indexCount}
app/controllers/pages\u controller.rb
类PagesController<应用程序控制器
#操作前:接受所有参数
@@staticCount=1
@@staticFlag=false
def主页
结束
def秀
如果参数[:标志]。是否存在?
@@staticFlag=ActiveModel::Type::Boolean.new.cast(参数[:标志])
如果@@staticFlag
@@staticCount=@@staticCount+1
其他的
@@staticCount=1
@@staticFlag=false
结束
其他的
@@staticCount=1
@@staticFlag=false
结束
@indexCount=@@staticCount
@flagCount=@@staticFlag
结束
私有的
#允许所有参数
#def接受所有参数
#许可证!
#结束
结束
运行方式:转到root_路径:
127.0.0.1:3000
,然后单击将_链接到零件,它将重新加载显示计数时间的页面,单击链接

所有事情都很容易理解,在将其值发送到服务器之前,请注意行
params.permit(:flag).merge(:flag=>true)
permit变量标志


快乐编码!:D

很不清楚“发送页面”是什么意思,也不清楚“在同一页面中的一列中查看对话\消息\路径页面(show.html.haml)”是什么意思。听起来有点像是在问AJAX,这是整本书的主题,而不是答案。也可能是。。。请编辑您的问题以增加清晰度,而不是评论。@max我更新了我的帖子,希望现在更清晰。