Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 模板未正确加载到轨道3中_Ruby On Rails_Ruby On Rails 3_Forms - Fatal编程技术网

Ruby on rails 模板未正确加载到轨道3中

Ruby on rails 模板未正确加载到轨道3中,ruby-on-rails,ruby-on-rails-3,forms,Ruby On Rails,Ruby On Rails 3,Forms,我在加载表单时遇到问题,不知道为什么会发生这种情况 问题:当我尝试加载表单(/messages/new)时,我得到一个空白页,没有错误消息 问题原因:我认为问题在于消息和用户之间的链接没有正确建立,这就是为什么表单没有正确加载,但不确定如何修复它 背景:我目前通过帖子/索引文件(附在下面)访问表单,但我认为这是错误的,因为每个用户都应该有一个唯一的链接…例如。如果我点击“联系人”按钮查看John创建的帖子,则该消息应发送给John,其他用户依此类推。我正在使用简单的私人消息插件 感谢您的反馈 谢

我在加载表单时遇到问题,不知道为什么会发生这种情况

问题:当我尝试加载表单(/messages/new)时,我得到一个空白页,没有错误消息

问题原因:我认为问题在于消息和用户之间的链接没有正确建立,这就是为什么表单没有正确加载,但不确定如何修复它

背景:我目前通过帖子/索引文件(附在下面)访问表单,但我认为这是错误的,因为每个用户都应该有一个唯一的链接…例如。如果我点击“联系人”按钮查看John创建的帖子,则该消息应发送给John,其他用户依此类推。我正在使用简单的私人消息插件

感谢您的反馈

谢谢

费萨尔

消息>新视图

<% form_for @message, :url => messages_path(:user_id => @user) do |f| %>
<p>
To:<br />
<%= f.text_field :to %>
<%= error_message_on @message, :to %>
</p>
<p>
Subject:<br />
<%= f.text_field :subject %>
<%= error_message_on @message, :subject %>
</p>
<p>
Message<br />
<%= f.text_area :body %>
<%= error_message_on @message, :body %>
</p>
<p>
<%= submit_tag "Send" %>
</p>
<% end %>
<table class="table table-striped">
<tbody>
<% @posts.each do |post| %>
<tr>
<td>I am a <%= post.title %> getting married in <%= post.job %> in <%= post.location %>, and looking for a <%= post.salary %>. My budget is <%= post.salary %>.</td>
<td> <button class="btn" data-toggle="button" onClick="javascript:location.href = '/messages/new';" />Contact</button></td>
<td><%= time_ago_in_words(post.created_at) %> ago.</td>
<!--/. 
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
-->
</tr>
<% end %>
</tbody>
</table>
消息控制器

class MessagesController < ApplicationController

before_filter :set_user

def index
if params[:mailbox] == "sent"
  @messages = @user.sent_messages
else
  @messages = @user.received_messages
end
end

def show
@message = Message.read_message(params[:id], current_user)
end

def new
@message = Message.new

if params[:reply_to]
  @reply_to = @user.received_messages.find(params[:reply_to])
  unless @reply_to.nil?
    @message.to = @reply_to.sender.login
    @message.subject = "Re: #{@reply_to.subject}"
    @message.body = "\n\n*Original message*\n\n #{@reply_to.body}"
  end
end
end

def create
@message = Message.new(params[:message])
@message.sender = @user
@message.recipient = User.find_by_login(params[:message][:to])

if @message.save
  flash[:notice] = "Message sent"
  redirect_to user_messages_path(@user)
else
  render :action => :new
end
end

def delete_selected
if request.post?
  if params[:delete]
    params[:delete].each { |id|
      @message = Message.find(:first, :conditions => ["messages.id = ? AND (sender_id = ? OR recipient_id = ?)", id, @user, @user])
      @message.mark_deleted(@user) unless @message.nil?
    }
    flash[:notice] = "Messages deleted"
  end
  redirect_to :back
end
end

private
def set_user
 @user = User.first
end
end
class messages控制器:新建
结束
结束
已选择def delete_
如果请求,请发邮件?
如果参数[:删除]
params[:delete]。每个{124; id|
@message=message.find(:first,:conditions=>[“messages.id=?AND(sender\u id=?或receiver\u id=?)”,id,@user,@user])
@message.mark_已删除(@user),除非@message.nil?
}
flash[:notice]=“已删除邮件”
结束
重定向到:返回
结束
结束
私有的
def set_用户
@user=user.first
结束
结束
帖子>索引视图

<% form_for @message, :url => messages_path(:user_id => @user) do |f| %>
<p>
To:<br />
<%= f.text_field :to %>
<%= error_message_on @message, :to %>
</p>
<p>
Subject:<br />
<%= f.text_field :subject %>
<%= error_message_on @message, :subject %>
</p>
<p>
Message<br />
<%= f.text_area :body %>
<%= error_message_on @message, :body %>
</p>
<p>
<%= submit_tag "Send" %>
</p>
<% end %>
<table class="table table-striped">
<tbody>
<% @posts.each do |post| %>
<tr>
<td>I am a <%= post.title %> getting married in <%= post.job %> in <%= post.location %>, and looking for a <%= post.salary %>. My budget is <%= post.salary %>.</td>
<td> <button class="btn" data-toggle="button" onClick="javascript:location.href = '/messages/new';" />Contact</button></td>
<td><%= time_ago_in_words(post.created_at) %> ago.</td>
<!--/. 
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
-->
</tr>
<% end %>
</tbody>
</table>

我是一个即将结婚的人,正在寻找一份工作。我的预算是。
接触
以前

消息/新行1,尝试将开头的ERB标记从无声更改为响亮


s/谢谢!!!它可以工作..但由于某些原因,如果我独立于任何用户(即直接)访问/messages/new,页面仍会打开..我如何禁用该功能?键入
ActionController::Redirecting
,以获取一些文档,说明如果不想让用户访问该页面,需要如何将用户重定向到该页面之外