Search Results

Search found 9437 results on 378 pages for 'rails newbie'.

Page 153/378 | < Previous Page | 149 150 151 152 153 154 155 156 157 158 159 160  | Next Page >

  • How do I create a point system in a Rails/Twitter app that assigns points to users and non-authentic

    - by codyvbrown
    I'm building a question and answer application on top of twitter and I'm hitting some snags because I'm inevitably dealing with two classes of users: authenticated and non-authenticated. The site enable users to give points to other users, who may or may not be authenticated, and I want to create a site-wide point system where the application stores and displays this information on their profile. I want to save this point data to the user because that would be faster and more efficient but non-authenticated users aren't in our system, we only have the twitter handle. So instead we display the points in our system like this: @points = point.all( :select => "tag, count(*) AS count", # Return tag and count :group => 'tag', # Group by the tag :order => "2 desc", :conditions => {:twitter_handle => params[:username]}) Is there a better way to do this? Is there a better way to associate data with non-authenticated users?

    Read the article

  • Suggestions for opening the Rails toolbox to design a challenge game?

    - by keruilin
    How would you suggest designing a challenge system as part of a food-eating game so that it's automated as possible? All RoR tools, design patterns and logic are at your disposal (e.g., admin consoles, crontab, arch, etc.). Prize goes to whoever can suggest the simplest and most-automated design! Here are the requirements: User has many challenges. Badge has many challenges. (A unique badge is awarded for each challenge won.) Only one challenge can run at a time. Each challenge has a limited number of days that it runs. For example, one challenge can run 3 days, while another runs 7 days. Challenges can be seasonal. For example, "Eat 13 Pumpkins" only runs during the Fall. New challenges are added to the game on an ongoing basis. For example, a new challenge every week. Each challenge has a certain probability of being selected to run. For example, "Eat 10 Pies" challenge has 10% chance of being selected to run. As each new challenge is added to the database, I want the probabilities of running to change dynamically. I want to avoid the scenario where I'm manually updating a database field just to change the probability from 10% to 5%, for example. Challenges act like Easter eggs. Challenge icons pop-up at different places on the webpage. User is awarded a badge for successfully completing a challenge, but only when it's active. There is some wait time between each challenge. Between 1 and 7 days. Which wait time is random, but the probability of the wait time being short is high and the probability of it being a long wait time is low.

    Read the article

  • In Rails, how do you functional test a Javascript response format?

    - by Teflon Ted
    If your controller action looks like this: respond_to do |format| format.html { raise 'Unsupported' } format.js # index.js.erb end and your functional test looks like this: test "javascript response..." do get :index end it will execute the HTML branch of the respond_to block. If you try this: test "javascript response..." do get 'index.js' end it executes the view (index.js.erb) withOUT running the controller action!

    Read the article

  • Should I send patch against 2-3-stable or master

    - by Nadal
    I am trying to find a way to contribute back to rails. I was thinking I should validate if this patch https://rails.lighthouseapp.com/projects/8994/tickets/4154-expires_now-broken works or not. I was able to validate the problem. The problem still exists in 2.3.5 and in 2-3-stable branch of rails. I was not able to apply his patch at 2-3-stable branch of rails . Also the patch failed for master branch. Looked at the diff and manually changed the code and the new code solves the bug. Now if I want to attach my patch to the ticket should I create my patch against 2-3-stable branch or master branch? I believe master is more closely aligned with rails3 changes.

    Read the article

  • Where to put a piece of code in Ruby on Rails?

    - by yuval
    I have a post controller that has many comments. The post model has a field called has_comments which is a boolean (so I can quickly select from the database only posts that have comments). To create a new comment for a post, I use the create action of my comments controller. After I create the comment I need to update my post's has_comments field and set it to true. I can update this field from the create action of my comments controller, but that doesn't seem right - I feel that I should really be using the post's update action, but I'm not sure if it's right to call it (via send?) from the create action of the comments controller. Where should the code for updating the post be? Thank you!

    Read the article

  • what else to do to establish many-to-many associations in Ruby on Rails? thanks!

    - by john
    Hi, I have two classes and I want to establish a many-to-many assications, here is the code: class Category < ActiveRecord::Base has_and_belongs_to_many :events has_and_belongs_to_many :tips end class Tip < ActiveRecord::Base has_and_belongs_to_many :categories However, I kept getting the following errors and I would appreciate it if some one could educate me what is going wrong: PGError: ERROR: relation "categories_tips" does not exist : SELECT "categories".id FROM "categories" INNER JOIN "categories_tips" ON "categories".id = "categories_tips".category_id WHERE ("categories_tips".tip_id = NULL ) the viewer part: 4: <%= text_field :tip, :title %></label></p> 5: 6: <p><label>Categories<br/> 7: <%= select_tag('categories[]', options_for_select(Category.find(:all).collect {|c| [c.name, c.id] }, @tip.category_ids), :multiple => true ) %></label></p> 8: 9: <p><label>Location<br/> 10: <%= text_field_with_auto_complete :tip, :abstract %></label></p>

    Read the article

  • how can I display controller's variable (which is on a loop) on .html.erb page? ruby on rails

    - by rrz
    I have the following code listed below in my controller: struc = {'en' => 'english', 'es' => 'espaniol', 'de' => 'germany', 'fr' => 'french', 'it' => 'italy'} struc.each_pair do |key, value| @key=key @value=value end on my application.html.erb I have the following <select name="Language" onchange="location=this.options[this.selectedIndex].value;"> <option value="/<% @key %>/<%= @rem %>"><%= @value %></option> </select> Now how can i make the value of '@key' and '@value' appear recursively display on (application.html.erb)? Thanks in advance

    Read the article

  • rails 3, active record: any way to tell how many unique values match a "x LIKE ?" query

    - by jpwynn
    I have a query to find all the phone numbers that match a partial expression such as "ends with 234" @matchingphones = Calls.find :all, :conditions => [ "(thephonenumber LIKE ?)", "%234"] The same phone number might be in the database several times, and so might be returned multiple times by this query if it matches. What I need is to know is UNIQUE phone numbers the query returns. For example if the database contains 000-111-1234 * 000-111-3333 000-111-2234 * 000-111-1234 * 000-111-4444 the existing query will return the 3 records marked with * (eg returns one phone number -1234 twice since it's in the database twice) what I need is a query that returns just once instance of each match, in this case 000-111-1234 * 000-111-2234 *

    Read the article

  • There is a JavaScript error in my rails application!

    - by Small Wolf
    As the title said, I got a problem! i encountered the "RJS Error:[object error]",the code in my application is page << "#{hidden_print("#{url_for(:controller => 'tables', :action => 'dispatch', :id => id, :pop => true, :print =>true)}")} " the method hidden_print is def hidden_print(url) "window.parent.headFrame.document.all.iframe_helper.src = '#{url}';" end

    Read the article

  • How can I get rails to not render escaped quotes as \&quot;

    - by James
    In my layout I have <% @current_user.popups.each do |p| %> <% content_for :script do %> <%= "$(document).ready ( function() { $.jGrowl(\"#{p.message}\", { sticky: true }) });" %> <% end %> <% end %> And then in the script section I have <%= yield :script %> The problem is that this renders the escaped quotes as \&quot; and javascript doesn't like this. How can I stop this from happening? Or is there another approach to this? I can't use single quotes because I'd like to have some html in the message. I'd appreciate any help.

    Read the article

  • remote_form_for in index.html.erb file not working w/ AJAX...Ruby on Rails...

    - by bgadoci
    Just curious if I am overlooking something simple here. I have deployed the remote_form_for in the show.html.erb code before to render comments on a post (project in this case) without a problem. I have moved this code to the index view and seems to degrade to the normal form_for action (page refresh). I am not getting any javascript errors so not sure what is wrong here. Here is my code: index.html.erb <% remote_form_for [project, Comment.new] do |f| %> <p> <%= f.label :body, "New Comment" %><br/> <%= f.text_area (:body, :class => "textarea") %> </p> <p> <%= f.label :name, "Name" %> (Required)<br/> <%= f.text_field (:name, :class => "textfield") %> </p> <p> <%= f.label :email, "Email" %> (Required but will not be displayed)<br/> <%= f.text_field (:email, :class => "textfield") %> </p> <p><%= f.submit "Add Comment" %></p> <% end %> CommentsController#create def create @project = Project.find(params[:project_id]) @comment = @project.comments.create!(params[:comment]) respond_to do |format| format.html { redirect_to projects_path } format.js end end /views/comments/create.js.rjs page.insert_html :bottom, :commentwrapper, :partial => @comment page[@comment].visual_effect :highlight page[:new_comment].reset page.replace_html :notice, flash[:notice] flash.discard /views/comments/_comment.html.erb <% div_for comment do %> <div id="commentwrapper"> <% if admin? %> <%=link_to_remote "X", :url => [@project, comment], :method => :delete %> <% end %> <%= h(comment.body) %><br/><br/> Posted <%= time_ago_in_words(comment.created_at) %> ago by <%= h(comment.name) %> <% if admin? %> | <%= h(comment.email) %> <% end %></div> <% end %>

    Read the article

  • How do I create another controller action to create an object in rails?

    - by Angela
    I have a model called Contact_Email. When an Email template is sent through ActionMailer to a specific Contact, as part of the Create action it sends it through upon .save. However, I want to create a "skip" action which also creates a Contact_Email, but does NOT send an ActionMailer and allows me to set the status differently. I want to create a separate action because I want to make this respond to a remote_for_tag so that I can just have an ajax button indicate it has been "skipped": Here's what I tried, but while it creates a Contact_Email, I end up getting an error when I want to go back and view all the Contacts again. def skip @contact_email = ContactEmail.new @contact_email.contact_id = params[:contact_id] @contact_email.email_id = params[:email_id] @contact_email.status = "skipped" if @contact_email.save flash[:notice] = "skipped email" redirect_to contact_emails_url end end

    Read the article

  • Rails - Why is my custom validation being triggered for only a build command.

    - by adam
    I have a sentence and correction model with a has_one and belongs_to relationship respectively. For some reason when I do def create @sentence = Sentence.find(params[:sentence_id]) @correction = @sentence.build_correction(params[:correction]) a custom validation I wrote for Correction is being called at the build_correction point. the validation is below class Correction < ActiveRecord::Base attr_accessible :text, :sentence_id, :user_id belongs_to :sentence belongs_to :user validate :correction_is_different_than_sentence def correction_is_different_than_sentence errors.add(:text, "can't be the same as the original sentence.") if (text == self.sentence.text) end the problem is for some reason on validation the correction object doesn't have the sentence id set (despite I used the build_correction method) and so it complains "you have nil object .... while executing nil.text" in the if clause in the validation above. So my question is why is the validation occuring for a build command, i thought it only triggers on a create or update. And why isnt the sentence_id getting set?

    Read the article

  • How do you render a rails partial that is outside of a namespace in a view that is inside of a namespace?

    - by iand675
    I've got a 'static' controller and static views that are pages that don't utilize ruby in their views. For these pages, I have a sitemap partial that is generated programatically and used in the application layout file. Namespaced routes still use the application layout file but are taking the static routes and trying to namespace them too. Here's the relevant portion of the route file: namespace :admin do resources :verse_categories resources :verses resources :songs resources :flowers resources :visits, :except => [:new, :create] end match ':action' => 'static' root :to => 'static#home' Here's the error I'm getting: No route matches {:controller=>"admin/static", :action=>"about"} Note that about is one of the static pages that the sitemap partial uses. So, how can I resolve this routing issue so that it's not trying to find my static sites inside of the admin namespace? Any help would be appreciated!

    Read the article

  • Rails: How to name and create unique divs within a loop?

    - by sscirrus
    I have a view with a div that is looped many times. Each of the created divs need to have a unique ID so I can access them specifically (at the moment, all my divs have the same ID specified in html so whenever I try to access a specific div it just finds the first one). This is the version that I currently have (multiple 'rowBox'es are not discernible). <% @customers.each do |customer| %> <div id="customer" class="rowBox"> ... </div> <% end %> I would like to be able to do something like: <% @customers.each do |customer| %> <div id="box<%=customer.id%>"> ... </div> <% end %> This doesn't seem to work. Any ideas on how to accomplish this?

    Read the article

< Previous Page | 149 150 151 152 153 154 155 156 157 158 159 160  | Next Page >