ruby-on-rails-4

share method in view and controller ruby on rails 4

妖精的绣舞 提交于 2020-01-14 05:23:21
问题 I have a method in my controller class class ProjectsController < ApplicationController def download_sftp some codes here end end and to be able to access it in my view,at the top of my controller I have this line helper_method :download_sftp when I use the following code in my view I get the undefined method download_sftp for this project <tbody> <% @projects.each do |project| %> <tr> <td><%= link_to 'download',project.download_sftp(project) %></td> </tr> <% end %> </tbody> 回答1: declaring a

flash[:alert] not working, but flash[:notice] displays the message on redirect

北慕城南 提交于 2020-01-14 04:59:04
问题 I am using rails_admin gem and the configuration is as follows config.authorize_with do if current_user.nil? || current_user.role != 'admin' redirect_to main_app.root_path flash[:alert] = "Sorry you are not authorized!" end end When I use flash[:notice] , I can see the message on the root_path, but if I change it to flash[:alert] it does not display, any ideas why and what would be the solution? I want to use :alert only, since changing the notice color will result it displaying red font for

How do I completely rid my Rails 4.2 application of teamcity?

ε祈祈猫儿з 提交于 2020-01-13 18:38:09
问题 I usually use Vim for Rails development and I decided to try out RubyMine to see what it was like. It wasn't half bad, but I decided it was too much bloat. Now however when I run rake test it is running tests "through" team city (I don't fully understand what it is doing). At no point do I recall installing teamcity. How can I completely get rid of it? Before my tests were running cleanly with guard and minitest/pride. Thank you. 回答1: I didn't try to understand what's happening but this

How to install sqlite or postgresql on windows 8 for a ruby on rails setup?

对着背影说爱祢 提交于 2020-01-13 16:30:31
问题 I've been trying to install a database as part of my ruby on rails setup. I'm running a 64 bit windows 8, a x64 based machine. My ruby version is 2.1.3p242, rails version is 4.0.0, sqlite3 version is 3.8.6 and postgresql version is 9.3 I first tried to install sqlite3 by following the steps given in this SO answer but I get this error `require': Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. My database.yml has

How to install sqlite or postgresql on windows 8 for a ruby on rails setup?

淺唱寂寞╮ 提交于 2020-01-13 16:30:14
问题 I've been trying to install a database as part of my ruby on rails setup. I'm running a 64 bit windows 8, a x64 based machine. My ruby version is 2.1.3p242, rails version is 4.0.0, sqlite3 version is 3.8.6 and postgresql version is 9.3 I first tried to install sqlite3 by following the steps given in this SO answer but I get this error `require': Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. My database.yml has

Creating an ActiveRecord object from another controller - am I doing it correctly?

三世轮回 提交于 2020-01-13 15:47:39
问题 I'm building a training website where I have two models, User and Course , that are associated with a third model, CourseCompletions . The third model is for keeping track of which user has completed which courses and vice versa. The first two models have controllers whereas the third one does not. I implemented the functionality for completing a course and it works (clicking the "complete course" button on the course page inserts the appropriate row into the course_completion table if the

Creating an ActiveRecord object from another controller - am I doing it correctly?

半世苍凉 提交于 2020-01-13 15:47:05
问题 I'm building a training website where I have two models, User and Course , that are associated with a third model, CourseCompletions . The third model is for keeping track of which user has completed which courses and vice versa. The first two models have controllers whereas the third one does not. I implemented the functionality for completing a course and it works (clicking the "complete course" button on the course page inserts the appropriate row into the course_completion table if the

Uninitialized constant ActionView::Helpers::InstanceTag in Rails 4

回眸只為那壹抹淺笑 提交于 2020-01-13 11:34:28
问题 I have the following code, which I use to customize form_for. I need to inherit ActionView::Helpers::InstanceTag class InstanceTag < ActionView::Helpers::InstanceTag I get exception after the upgrade to Rails 4 and I saw that in the docs there is no such class. What is the best class to use instead of it? 回答1: After some research. I found that ActionView::Helpers::InstanceTag is transformed into module called ActiveModelInstanceTag ActionView::Helpers::ActiveModelInstanceTag 来源: https:/

Uninitialized constant ActionView::Helpers::InstanceTag in Rails 4

拟墨画扇 提交于 2020-01-13 11:33:10
问题 I have the following code, which I use to customize form_for. I need to inherit ActionView::Helpers::InstanceTag class InstanceTag < ActionView::Helpers::InstanceTag I get exception after the upgrade to Rails 4 and I saw that in the docs there is no such class. What is the best class to use instead of it? 回答1: After some research. I found that ActionView::Helpers::InstanceTag is transformed into module called ActiveModelInstanceTag ActionView::Helpers::ActiveModelInstanceTag 来源: https:/

Rails 4. Country validation in model

我的梦境 提交于 2020-01-13 11:25:10
问题 I'm creating rails API and want to want to add validation for countries field which contains an ISO 3166-1 code on model level. For example if use gem carmen-rails, it provides only helper country_select . Is that way to use validation for accordance country for ISO 3166-1 code in the model? 回答1: You are just trying to validate that the country code entered is appropriate? this should work with carmen validates :country, inclusion:{in:Carmen::Country.all.map(&:code)} But if this is all you