轨道3和SQLite关于boolians通信 [英] Rails 3 and SQLite communications concerning boolians

查看:161
本文介绍了轨道3和SQLite关于boolians通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Rails 3.2.8和SQLite 1.3.6 IM

im using Rails 3.2.8 and SQLite 1.3.6

和IM运行到麻烦不断变化boolian变量在数据库中

and im running into troubles changing boolian variables in the database

SQLite的转化的T和f为真和假

SQLite translates "t" and "f" as true and false

此功能不会更新:批准属性(也就是默认为false)

this function wont update the :approved attribute (that is default false)

def activate
  @user = User.find(params[:id])

  if @user.update_attribute(:approved, 't')

    redirect_to "/" #this is the return i get so the update returns true

  else
   render "/users?approved=false"
  end 
end

但像改变字符串@ user.update_attribute(:电子邮件,根@ email.org')将更新电子邮件

如何解决这个我需要某种形式的sqlite的适配器的?

how can i fix this do i need some kind of an sqlite adapter ?

我已经安装了的ActiveRecord-jdbcsqlite3适配器,它搞砸了我的应用程序,因为我太草率,并没有注意到,这是德precated:P

i already installed activerecord-jdbcsqlite3-adapter and it messed up my app because i was too hasty and didnt notice that it was deprecated :P

我发现这个线程:轨道3 sqlite3的布尔假
但我不明白,我需要为了让Rails和SQLite的正常通信做即时通讯作为在轨新手:)

i found this thread : Rails 3 SQLite3 Boolean false but i dont understand what i need to do in order to make Rails and SQLite communicate correctly as im a newbie in rails :)

也是我认为它值得一提的IM运行在Windows 7这个64

also i think its worth mentioning that im running this on windows 7 x64

更新

显然Rails的确实知道如何使用SQLite沟通,但我不知道为什么我的code为boolians dosnt工作笑

Apparently Rails does indeed know how to communicate with Sqlite, but the i have no idea why my code dosnt work for boolians lol

在我看来,我有:

<% @users.each do |user| %> 
<tr> 
  <td><%= user.id %></td> 
  <td><%= user.email %></td>
  <td><%= user.approved? %></td>
  <td>
<% if !user.approved? %>
  <%= link_to 'Approve', active_user_path(user), :method => :put %> 
    <% end %> </td> 
</tr> 
<% end %> 

这列出了所有未经批准的用户和链接激活它们(设置布尔为true)

This lists all the unapproved users and a link to activate them (set the bool to true)

和在我的控制器我有

    def activate
      @user = User.find(params[:id])

    if @user.update_attribute(:approved, true)

      redirect_to "/" #this is the return i get so the update returns true

    else
      render "/users?approved=false" #this is not rendered
    end 
  end

和我的路线

match "users/:id/activate" => "users#activate", :as => "active_user"

这适用于其他字符串,如用户的姓名,地址等,但不是布尔的

This works for other strings like the user name, address etc but not the bool's

推荐答案

我解决了这个用整数移植到我的用户表,我不知道为什么作为的@ user.update_attribute(:批准,真)剪掉保存到数据库,它必须有一些东西跟我的设置

I solved this by using a integer migration to my users table, i have no idea as of why @user.update_attribute(:approved, true) didnt save to the database it must have had something to do with my setup

我所做的迁移 add_column:用户:is_approved,整数,:默认=&GT; 0 键,当我要激活用户,我只是翻转整数值1

i made the migration add_column :users, :is_approved, :integer, :default => 0 and when i want to activate a user i simply flip the integer value to 1

这篇关于轨道3和SQLite关于boolians通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆