简体   繁体   English

Rails 3通知

[英]Rails 3 notices

Using Rails 3.0.3 in combination with gems like devise I don't get any flash messages. 使用Rails 3.0.3结合设计之类的宝石我没有得到任何flash消息。 Now I mention devise, because it controls the cookies used to authenticate me. 现在我提到设计,因为它控制用于验证我的cookie。

Now the Rails application is a bit special since its using sub-domains . 现在Rails应用程序有点特殊,因为它使用子域 What they do is tell the application which company a user is browsing. 他们所做的是告诉应用程序用户正在浏览哪家公司。 An example: mycompany.theapp.com/projects/3/ <- Project 3 of company "mycompany". 例如:mycompany.theapp.com/projects/3/ < - 公司“mycompany”的项目3。
When a user logs in he/she is directed to theapp.com/overview <- non subdomain 当用户登录时,他/她被定向到theapp.com/overview < - 非子域
Every notice there does show, so why not on sub-domain pages? 那里的每一个通知都会显示,为什么不在子域名页面上呢?

So this is the code used on sub-domain pages. 所以这是子域页面上使用的代码。 Exactly the same as one would put it on non-sub-domain pages. 与将其放在非子域页面上的完全相同。 The code in the controller: 控制器中的代码:

def update
  redirect_to [@project], :notice => "Project #{@project.name} updated."
end

The layouts/application.html.erb layouts / application.html.erb

<% flash.each do |type, message| %>
  <%= content_tag :div, message, :class => "flash #{type}" %>
<% end %>

I also added the following, trying to figure out what is happening: 我还添加了以下内容,试图弄清楚发生了什么:

flash.to_yaml
# Result: --- !map:ActionDispatch::Flash::FlashHash {} 

Since apparently devise uses flash[:notice] I also tried that (because that was working for devise). 由于显然设计使用flash [:notice]我也尝试过(因为那是为了设计)。

flash[:notice] = "Project #{@project.name} updated."
# Result: --- !map:ActionDispatch::Flash::FlashHash {} 

Now do the notices get send by cookies or session data that isn't transferred well to sub-domains? 现在,通知是否会通过cookie或会话数据发送,而这些数据不能很好地传输到子域? Because the edit form of the project is on mycompany.theapp.com/projects/3/edit/ 因为项目的编辑形式在mycompany.theapp.com/projects/3/edit/
And it sends me to mycompany.theapp.com/projects/3/ (without notice) 它将我发送到mycompany.theapp.com/projects/3/(不另行通知)

It happens on Ubuntu 10.10 with "rails server", passenger using nginx and even on a Mac machine (but someone else tested that). 它发生在带有“rails服务器”的Ubuntu 10.10上,乘客使用nginx甚至在Mac机器上(但其他人测试过)。

Anyone care to guess? 有人在乎猜?

Apparently there wasn't really something wrong with the configuration. 显然,配置并没有什么问题。 We deployed it on a server real quick, production mode, and it worked, much to our surprise. 我们将它部署在服务器上,实时快速,生产模式,并且它起作用,令我们惊讶。 The notices were showing up across all domains. 这些通知显示在所有域中。
It's something with localhost domains, I was using lvh.me, that Rails doesn't quite get. 这是localhost域的东西,我使用的是lvh.me,Rails并不是很好。

The hint was in a (recent) comment on a railscast: 该提示是在(最近)对railscast的评论中:

http://railscasts.com/episodes/221-subdomains-in-rails-3?view=comments#comment_146276 There's one important thing to know if you want to share sessions between subdomains on localhost. http://railscasts.com/episodes/221-subdomains-in-rails-3?view=comments#comment_146276如果您想在localhost上的子域之间共享会话,有一件重要的事情要知道。 Using :domain => ".lvh.me" not always works (in my case it didn't), so you have to configure your environment as described in blog.plataformatec.com.br/2009/12/subdomains-and-sessions-to-the-rescue/ 使用:domain =>“。lvh.me”并不总是有效(在我的情况下它没有),所以你必须按照blog.plataformatec.com.br/2009/12/subdomains-and-中的描述配置你的环境。 会议对在救援/

@David Sulc, the users were logged in. @David Sulc,用户已登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM