小编Hun*_*ter的帖子

Rails重定向不会像HTML那样

我有一个注册表单,如果注册成功,应该将用户重定向到他们的个人资料.如果注册失败,我想在不使用Javascript重新加载页面的情况下发出错误消息.

这是我的表单标题:

<%= form_for resource, as: resource_name, url: registration_path(resource_name), remote: true do |f| %>
Run Code Online (Sandbox Code Playgroud)

我的注册管理员:

def create
  respond_to do |format|
    if resource.saved
      sign_up(resource_name, resource)
      format.html { redirect_to current_employer }
    else
      format.js { render 'employers/sign_up_failure' }
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

所以失败有效.它在表单上方显示错误消息而不重新加载页面.注册成功format.html { redirect_to current_employer }不工作.

我的服务器日志说重定向已经处理:

Redirected to http://localhost:3000/employers/27
Run Code Online (Sandbox Code Playgroud)

但看起来我的Employers控制器上的show动作被称为Javascript:

Processing by EmployersController#show as JS
Run Code Online (Sandbox Code Playgroud)

因此,当我提交表单时,它不会将我重定向到我的个人资料页面.页面不闪烁.我登录但是,如果我刷新页面,则表明我已登录.

顺便说一句,我正在使用Devise,我的注册控制器是对Devise使用的修正.

不知道为什么这不起作用.我已经取出了format.js {}部分,它仍然通过JS向我的雇主#Show行动发送GET调用.我想要的是将重定向格式化为HTML并将我带到配置文件页面.

有任何想法吗?

解决方案 谢谢你的帮助.面掌,我完全忘记了remote: true工作原理.这是我实施的解决方案......希望有人发现这很有用.

def create
  respond_to do |format|
    if resource.saved
      sign_up(resource_name, resource)
      #CHANGED
      format.js …
Run Code Online (Sandbox Code Playgroud)

javascript format redirect ruby-on-rails

6
推荐指数
1
解决办法
1481
查看次数

Google Places API评论小部件

我正在尝试将Google的“撰写评论”窗口小部件嵌入我的网站。很像Podium.com所做的。

他们托管一个页面并使用src加载iframe:

https://www.google.com/maps/api/js/ReviewsService.LoadWriteWidget?key=THEIR_API_KEY&pb=!2m1!1sChIJ6VFjYpqa9YgREIJTX-XLyoE!3shttps%3A%2F%2Ftheir-url.com!5sen&cb=37369878
Run Code Online (Sandbox Code Playgroud)

如此绘制小部件: 写评论小部件

我挖了他们的html来源,看来他们正在使用Google地方信息评论小部件。我在GoogleGoogle Developers上搜索了“ Google地方信息评论小部件”,它返回了结果:

搜索结果列表

但是,链接转到404页面:

我已经使用API​​密钥在自己的页面上复制了Podium所做的事情。但是,小部件不会显示。我没有收到任何错误,iframe加载了一些脚本和一些隐藏的html元素,但没有呈现完整的小部件。

这是我无法访问的API或功能吗?有没有人实现类似的东西?

google-maps google-maps-api-3 google-places-api

5
推荐指数
1
解决办法
1521
查看次数

Heroku rake资产:预编译无法编译Rails应用程序

我没有对我的资产进行任何更改,现在突然间,当我执行git push heroku master时,它会对rake资产中止:precompile

...

Preparing app for Rails asset pipeline
Running: rake assets:precompile
I, [2014-03-14T18:30:05.776041 #675]  INFO -- : Writing /tmp/build_f664cf41-71b7-435d-b85e-8f607080a4d3/public/assets/application-0a41bdbc9b8fc13f1e62a69634eb2c98.js
rake aborted!
wrong number of arguments (2 for 1)
(in /tmp/build_f664cf41-71b7-435d-b85e-8f607080a4d3/app/assets/stylesheets/application.css.scss)
/tmp/build_f664cf41-71b7-435d-b85e-8f607080a4d3/vendor/bundle/ruby/2.0.0/gems/sass-3.2.14/lib/sass/importers/filesystem.rb:16:in `initialize'
/tmp/build_f664cf41-71b7-435d-b85e-8f607080a4d3/vendor/bundle/ruby/2.0.0/gems/sprockets-2.12.0/lib/sprockets/sass_importer.rb:11:in `initialize'

...

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
!
!     Precompiling assets failed.
!

!     Push rejected, failed to compile Ruby app
Run Code Online (Sandbox Code Playgroud)

它看起来像是在资产/样式表/ application.css.scss中错误的参数数量(2比1).但我的样式表中没有任何方法.这是那个文件:

/*
* This is a manifest …
Run Code Online (Sandbox Code Playgroud)

assets ruby-on-rails heroku precompile

3
推荐指数
1
解决办法
1455
查看次数