小编Aka*_*aka的帖子

POST登录路由在生产中不起作用

我是红宝石的新手。我正在开发具有身份验证系统的应用程序。
我的问题是在生产环境(Heroku)中登录应用程序时出现错误。它正在开发中。 输入url https://akashpinnaka.herokuapp.com/login后产生

错误,它重定向到https://akashpinnaka.herokuapp.comlogin。我缺少用于POST登录的root_url和'login'之间的'/'。注意:在开发环境中工作。我的路线是



Rails.application.routes.draw do

get 'welcome/index'
root 'welcome#index'
resources :articles
resources :projects
resources :users

get '/login' => 'sessions#new'
post '/login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'

end
Run Code Online (Sandbox Code Playgroud)

会话控制器

class SessionsController < ApplicationController

  def new
  end

  def create
    @user = User.find_by_email(params[:session][:email])
    if @user && @user.authenticate(params[:session][:password])
      session[:user_id] = @user.id
      redirect_to root_path
    else
      redirect_to 'login'
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to '/'
  end

end
Run Code Online (Sandbox Code Playgroud)

会话数#新

<%= form_for(:session, url: login_path) do |f| …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails heroku url-routing production-environment

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

在 OSX catalina(10.15.1) 中使用 rbenv 安装 ruby​​-2.4.0 时,构建失败(OS X 10.15.1 使用 ruby​​-build 20191124)

我从在线论坛上尝试了很多东西。但从来没有工作过。安装Xcode以查看它是否有效。但事实并非如此。

起初,在安装 OpenSSL 时 C 可执行文件存在问题。但是后来,我从这里发现,由于安装Anaconda而出现错误。所以我卸载了anaconda并尝试再次安装。

但现在它抛出了一个不同的错误。

? ~ rbenv install 2.4.0 正在下载 openssl-1.1.0j.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/31bec6c203ce1a8e93d5994f4ed304c63ccf07676118b12676118b12676118b12676118b12676118b12676118b12631bs18b12631b10ds.openss18b12631b1.0.openss18b12631ds1.0 . /akashpinnaka/.rbenv/versions/2.4.0

正在下载 ruby​​-2.4.0.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.bz2 正在安装 ruby​​-2.4.0.. . ruby​​-build:使用自制软件的 readline

构建失败(OS X 10.15.1 使用 ruby​​-build 20191124)

检查或清理工作树在/var/folders/xs/gy8wglwj22g9lbhqfv9mwp7m0000gn/T/ruby-build.20191205014031.81437.0Fmlfl结果记录到/var/folders/xs/gy8wglwj22g9lbhqfv9mwp7m0000gn/T/ruby-build.20191205014031.81437.log

最后 10 行日志:num2int.c:64:5:注意:要匹配这个 '(' sprintf(buf, "%"PRI_LL_PREFIX"u", NUM2ULL(num)); ^ /usr/local/include/secure/_stdio .h:47:27: 注意:从内置宏 'sprintf' 扩展 ___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS ) ^ 190 个警告和 2 个错误生成。make [2]: * [num2int.o] Error 1 make 1 : * [ext/-test-/num2int/all] 错误 2 制作:*** [build-ext] 错误 2 …

ruby macos ruby-on-rails rbenv anaconda

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

如何在rails控制器中设置html类属性?

我是铁杆初学者.我在通知控制器中使用after_action.
通知控制器

class NotificationsController < ApplicationController

    layout "posts"

    after_action :read_message, only: [:index]

    def index
        @notifications = Notification.where(:recipient_id => session[:registered_id]).order("created_at DESC")

    end

    def new
        @user = User.find(session[:user_id])
        @notification = @user.notifications.new
    end

    def create
        @user = User.find(session[:user_id])
        @notification = @user.notifications.new notification_params
        if @notification.save
            redirect_to(:controller => "posts", :action => "index")
        else
            render "new"
        end
    end

    private

    def notification_params
        params.require(:notification).permit(:message, :user_id, :recipient_id, :status)
    end

    def read_message
        @notifications = Notification.where(:recipient_id => session[:registered_id]).order("created_at DESC")
        @notifications.read_all
    end

end
Run Code Online (Sandbox Code Playgroud)

通知#index视图

 <% @notifications.each do |notification| %>
   <div class …
Run Code Online (Sandbox Code Playgroud)

ruby attributes ruby-on-rails class

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