ruby-on-rails-3

Displaying posts by specific user?

爱⌒轻易说出口 提交于 2019-12-24 22:18:57
问题 Here I have some code: def show @post = Post.find() end end the user model has has_many :posts and the post model has belongs_to :user. Now how can I make the show action only display posts by the user logged in. User logged in is "current_user"? 回答1: You could do this: def show @post = Post.where(user_id: current_user.id) end But there is glitch with the variable, you should rename @post to @posts since this will be an array of several Posts (if so, don't forget to change the variable in

How to add a new flash message to devise.en.yml?

旧街凉风 提交于 2019-12-24 22:18:26
问题 I want to display a new flash msg on logout under a particular condition.. I'm overriding the after_sign_out_path_for method in application_controller.rb . I have added a new msg in devise.en.yml too. How do I flash the new msg on logout when its redirected to sign in page??? application_controller.rb: def after_sign_out_path_for(resource_or_scope) if is_already_logged_in? flash.keep[:notice] = t("devise.failure.concurrent")// IS NOT WORKING new_user_session_path else new_user_session_path

How to implement generators for a plugin located at the `lib/<plugin_name>` directory?

若如初见. 提交于 2019-12-24 21:54:11
问题 I am using Ruby on Rails 3.2.2. I have implemented a Something plugin (it is almost a gem, but is not a gem) and all related files are in the lib/something directory. Since I would like to automate code generation related to that plugin, I came up with Ruby on Rails Generators. So, for the Something plugin , I am looking for implementing my own generators in the lib/something directory. How should I make that and what are prescriptions? That is, for example, what rails generate command line

Rails 3.0.9 + open_id_authentication

不羁岁月 提交于 2019-12-24 21:25:13
问题 I'm using open_id_authentication gem to authenticate to google. In my sessions controller I call authenticate_with_open_id(complete_identity_url, OPENID_OPTS) do |openid_result, identity_url, registration| and it returns 401 status code Unauthenticated. But it should show google page in which I must confirm access. I made example app: https://github.com/mbashirov/rails3-test, it only has code in sessions controller and routes set. That code works perfectly on rails 2.3 app. There is error?

Saving and redirecting with a model and revision model in Rails

北慕城南 提交于 2019-12-24 20:55:21
问题 I'm relatively new to RoR, and have been working on a lesson-site sharing back-end. Currently I have two models: Lesson and Revision. The idea is that a teacher would create a lesson (with a title, description, etc.), at the lesson/new page. The form would redirect to another form with other fields (content, comments) at the lesson/lesson_id/revision/new page. Eventually teachers will be able to "save and modify" lessons by copying revisions to their own profile, but the model isn't there yet

Client timeout on AWS Couchbase cluster after upgrading to Ruby 1.9.3

杀马特。学长 韩版系。学妹 提交于 2019-12-24 20:49:57
问题 After we upgrade to Rails 3.2.8 with Ruby 1.9.3 (from 1.8.7), our Couchbase client could no longer access our AWS cluster (Couchbase 1.8 Community Edition). 1.9.3p194 :011 > c = Couchbase.new("http://ec2-184-169-237-63.us-west-1.compute.amazonaws.com:8091") => #<Couchbase::Bucket:0x007fe12d9e6c98 "http://ec2-184-169-237-63.us-west-1.compute.amazonaws.com:8091/pools/default/buckets/default/" default_format=:document, default_flags=0x0, quiet=false, connected=true, timeout=2500000> 1.9.3p194

How to hold the checkbox params in rails after search

好久不见. 提交于 2019-12-24 20:45:56
问题 The search is working fine but the problem is that when i print the excel report according to the result.it is showing all the values in the database, filter is not working.Realoding all over the page, then Checkbox true values are gone. How to hold the params after refreshing the page .row .col-md-3 = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]","CUS", false = label_tag "Organizational Customer" .col-md-3 = check_box_tag "search_customer_supplier[accounts

Ajax action won't reflect on appearance but the value. Why?

我的梦境 提交于 2019-12-24 20:42:04
问题 I'm using Rails3. Now trying to implement follow button in index.html.erb just like twitter. It shows member list and their follow buttons. It looks okay but if I press any of those follow button, appearance doesn't change. It should changes follow to un-follow right away. I have no idea why it does. But if I reload the page, it shows correct status. follows_controller.rb class FollowsController < ApplicationController def create @user = User.find(params[:user_id]) current_user.follow(@user)

undefined local variable or method `params' for #<Result:0x3904b18>

a 夏天 提交于 2019-12-24 20:41:41
问题 I have a method defined in my model def generate_result self.ncbi_ref_seq=params[:ncbi_ref_seq] Bio::NCBI.default_email = "haha@hotmail.com" fasta_sequence= Bio::NCBI::REST::EFetch.nucleotide(@result.ncbi_ref_seq,"fasta") fasta=Bio::FastaFormat.new(fasta_sequence) self.genome_seq = fasta.data self.genome_sample = fasta.definition end In the view, I pass the ncbi_ref_seq value using the following method: <%= form_for(@result) do |f| %> <% if @result.errors.any? %> <div id="error_explanation">

How do I apply one of two classes to an image depending on a certain condition in Rails 3?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 20:25:49
问题 So for one class, I would do something like: <%= image_tag(upload.image.url, :class => upload.upvoted? ? 'upvoted' : nil) %> But I want to have it check to see if downvoted applies, and if so applies the class downvoted'. If it doesn't apply, it checks to see if upvoted` does, and then applies that class. 回答1: I would move the logic for determining the class to a helper method: apps/helpers/stage_helper.rb module StageHelper def upload_class(upload) if upload.upvoted? 'upvoted' elsif upload