Search Results

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

Page 104/378 | < Previous Page | 100 101 102 103 104 105 106 107 108 109 110 111  | Next Page >

  • [Ruby on Rails] Data Structure

    - by siulamvictor
    I am building a online form, with about 20 multiple choice checkboxes. I can get the nested data with this command. raise params.to_yaml I need to store these data and call them again later. I want to sort out which user chose which specific checkbox, i.e. who chose checkbox no.2? What's the best way to store these data in database?

    Read the article

  • Rails newb syntax question

    - by Veep
    I'm in the console, looking at someone else's app. I come across the following: >> p.location => [#<Tag id: 2, name: "projects">] Why do I see this result, which seems to be the object name, and how do I access the actual attribute name, "projects"? >> p.location.name => "Tag" Thank you very much!

    Read the article

  • How to sanitize sql fragment in Rails

    - by dimus
    I have to sanitize a part of sql query. I can do something like this: class << ActiveRecord::Base public :sanitize_sql end str = ActiveRecord::Base.sanitize_sql(["AND column1 = ?", "two's"], '') But it is not safe because I expose protected method. What is a better way to do it?

    Read the article

  • JQuery date picker does not firing in ajax page using Rails

    - by prabu
    Hi Here I have using datepicker from JQueryUI in my public/javascript folder as effects,prototype,control,dragdrop js files. in my public folder contains jqueryui development buddle. (css,js,development-bundle) in layout/application.rhtml <%= stylesheet_link_tag 'application' %> <%=javascript_include_tag :defaults%> <%= stylesheet_link_tag '/jquery-ui/css/custom-theme/jquery-ui-1.8.1.custom.css' %> <%=javascript_include_tag "/jquery-ui/js/jquery-1.4.2.min.js"%> <%=javascript_include_tag "/jquery-ui/js/jquery-ui-1.8.1.custom.min.js"%> <script> $(document).ready(function(){ var $j=jQuery.noConflict(); $j( '#date' ).datepicker({ dateFormat: 'dd-mm-yy' }); }); </script> in home/index.rhtml <%title "Home"%> <%=link_to "Add Details" ,:action=>"add"%> <%=link_to_remote "Ajax Add Details", :update=>"add" , :url=>{ :action=>"add" }%> <div id='add' /> in home/add.rhtml <%title "Add details"%> <%form_tag :action=>"create" do%> Name : <%=text_field_tag "name" ,"",:size=>15%> DOB : <%=text_field_tag "dob","",:id=>"date"%> <%=submit_tag "Save"%> <%end%> the datepicker works when I run home/add.rhtml directly but the datepicker not work when i run ajax page home/index.rhtml Any solutions for that,????

    Read the article

  • Overriding content_type for Rails Paperclip plugin

    - by Fotios
    I think I have a bit of a chicken and egg problem. I would like to set the content_type of a file uploaded via Paperclip. The problem is that the default content_type is only based on extension, but I'd like to base it on another module. I seem to be able to set the content_type with the before_post_process class Upload < ActiveRecord::Base has_attached_file :upload before_post_process :foo def foo logger.debug "Changing content_type" #This works self.upload.instance_write(:content_type,"foobar") # This fails because the file does not actually exist yet self.upload.instance_write(:content_type,file_type(self.upload.path) end # Returns the filetype based on file command (assume it works) def file_type(path) return `file -ib '#{path}'`.split(/;/)[0] end end But...I cannot base the content type on the file because Paperclip doesn't write the file until after_create. And I cannot seem to set the content_type after it has been saved or with the after_create callback (even back in the controller) So I would like to know if I can somehow get access to the actual file object (assume there are no processors doing anything to the original file) before it is saved, so that I can run the file_type command on that. Or is there a way to modify the content_type after the objects have been created.

    Read the article

  • Problems with rails and saving to the database.

    - by Grantismo
    I've been having some difficulty in understanding the source of a problem. Below is a listing of the model classes. Essentially the goal is to have the ability to add sentences to the end of the story, or to add stories to an existing sentence_block. Right now, I'm only attempting to allow users to add sentences, and automatically create a new sentence_block for the new sentence. class Story < ActiveRecord::Base has_many :sentence_blocks, :dependent => :destroy has_many :sentences, :through => :sentence_blocks accepts_nested_attributes_for :sentence_blocks end class SentenceBlock < ActiveRecord::Base belongs_to :story has_many :sentences, :dependent => :destroy end class Sentence < ActiveRecord::Base belongs_to :sentence_block def story @sentence_block = SentenceBlock.find(self.sentence_block_id) Story.find(@sentence_block.story_id) end end The problem is occurring when using the show method of the Story. The Story method is as follows, and the associated show method for a sentence is also included. Sentence.show def show @sentence = Sentence.find(params[:id]) respond_to do |format| format.html {redirect_to(@sentence.story)} format.xml { render :xml => @sentence } end end Story.show def show @story = Story.find(params[:id]) @sentence_block = @story.sentence_blocks.build @new_sentence = @sentence_block.sentences.build(params[:sentence]) respond_to do |format| if @new_sentence.content != nil and @new_sentence.sentence_block_id != nil and @sentence_block.save and @new_sentence.save flash[:notice] = 'Sentence was successfully added.' format.html # new.html.erb format.xml { render :xml => @story } else @sentence_block.destroy format.html format.xml { render :xml => @story } end end end I'm getting a "couldn't find Sentence_block without and id" error. So I'm assuming that for some reason the sentence_block isn't getting saved to the database. Can anyone help me with my understanding of the behavior and why I'm getting the error? I'm trying to ensure that every time the view depicts show for a story, an unnecessary sentence_block and sentence isn't created, unless someone submits the form, I'm not really sure how to accomplish this. Any help would be appreciated.

    Read the article

  • Rails, Edit page update in a window

    - by Mike
    I have my code working so that I have a table of businesses. There's a pencil icon you can click on the edit the business information. The edit information comes up in a partial inside of a modal pop up box. The only problem is that once they make the changes they want and click update, it sends them to the 'show' page for that business. What I want to happen is have the pop up box close and have it update the information. This is my update function in my controller. def update @business = Business.find(params[:id]) respond_to do |format| if @business.update_attributes(params[:business]) flash[:notice] = 'Business was successfully updated.' format.html { redirect_to(business_url(@business)) } format.js else format.html { render :action => "edit" } format.xml { render :xml => @business.errors, :status => :unprocessable_entity } end end end I tried following railscast 43 and i created an .rjs file but I couldn't get that to work at all. My update was still taking me to the show page. Any help would be appreciated. EDIT: Added some more code. <% form_for(@business) do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> ... <%= f.label :business_category %><br /> <%= f.select :business_category_id, @business_categories_map, :selected => @business.business_category_id %> </p> <p> <%= f.label :description %><br /> <%= f.text_area :description %> </p> <p> <%= f.submit 'Update' %> </p> <% end %> This is my form inside of my edit page which is being called through the index in a pop up by: <div id="popupEdit<%=h business.id %>" class="popupContact"> <a class="popupClose<%=h business.id %>" id="popupClose">x</a> <% if business.business_category_id %> <% @business = business %> <%= render "business/edit" %> <% end %> </div>

    Read the article

  • rails, activerecord callbacks not saving

    - by Joseph Silvashy
    I have a model with a callback that runs after_update: after_update :set_state protected def set_state if self.valid? self.state = 'complete' else self.state = 'in_progress' end end But it doesn't actually save those values, why not? Regardless of if the model is valid or not it won't even write anything, even if i remove the if self.valid? condition, I can't seem to save the state. Um, this might sound dumb, do I need to run save on it?

    Read the article

  • Nokogiri parsing Rackspace return using XPath in Rails

    - by Schroedinger
    Hey guys, I'm using Nokogiri to parse a return from the Rackspace API so I'm using their sample code to response = server.get '/customers/'[email protected]_id.to_s+'/domains/', server.xml_format doc = Nokogiri::XML::parse response.body puts "xpath values" doc.xpath("//name").each do |node| puts node.text end As my code to use Nokogiri to return the nodelist of nodes of the element for some reason I seem to have missed something obvious and I just for the life of me cannot get it to parse the list of nodes and return them to me, is there something simple I can do to fix to have it return the list of nodes? Cheers

    Read the article

  • Sanitizing CSS in Rails

    - by Erik
    Hello! I want to allow the users of a web app that I'm building to write their own CSS in order to customize their profile page. However I am aware of this opening up for many security risks, i e background: url('javascript:alert("Got your cookies! " + document.cookies'). Hence I am looking for a solution to sanitize the CSS while still allowing as much CSS functionality as possible for my users. So my questions if anyone anyone knows of a gem or a plugin to handles this? I've googled my brains out already so any tips would be really appreciated!

    Read the article

  • Rails / JBuilder - Entity array with has_many attributes

    - by seufagner
    I have two models, Person and Image and I want return an json array of Persons with your Images. But I dont want return all Image attributes, but produces a different result. Code below: class Person < ActiveRecord::Base has_many :images, as: :imageable validates :name, presence: true accepts_nested_attributes_for :images, :reject_if => lambda { |img| img['asset'].blank? } end class Image < ActiveRecord::Base belongs_to :imageable, polymorphic: true mount_uploader :asset, ImageUploader validates :asset, presence: true end zzz.jbuilder.json template json.persons(@rodas, :id, :name, :images) json produced: { "rodas": [{ "id": 4, "name": "John", "images": [ { "asset": { "url": "/uploads/image/xxxx.png" } }, { "asset": { "url": "/uploads/image/yyyyy.jpeg" } } ]}, { "id": 19, "name": "Mary", "images": [ { "asset": { "url": "/uploads/image/kkkkkkk.png" } } ] }] } I want something like: { "rodas": [ { "id": 4, "name": "John", "images": [ "/uploads/image/xxxx.png" , "/uploads/image/yyyy.jpeg" ] }, { "id": 10, "name": "Mary", "images": [ "/uploads/image/dddd.png" , "/uploads/image/xxxx.jpeg" ] } ]}

    Read the article

  • Rails time zone selector: intelligently selecting a default

    - by Tim Sullivan
    When signing up for an account on one of my apps, we need to store the time zone is in. We're using the time zone selector, which is fine, but I'd like to set the default value to something that it likely the user's current time zone. Is there an easy way, either on the server or using JavaScript, to set the time zone selector to the time zone the user is currently in?

    Read the article

  • Needed help with deleting rails cache

    - by WarDoGG
    I have been given a project of editing a website which is coded in RoR. However, the changes which i make in the view file is not visible immediately after a hard refresh but after 15-20 mins, the changes reflect. I am guessing this has something to do with the RoR caching system. Can someone please help me out ? The changes i made are purely HTML based like changing HTML attributes, filenames etc...

    Read the article

  • Where to put to_xls and from_xls in a rails app

    - by Joe Arasin
    So I have a model that I need to be able to serialize to/read from an Excel(XLS) document. I am a bit of a loss as to where this code actually belongs. My initial thought is that the to_xls is a view, but after poking around and seeing things like (to|from)_xml and (to|from)_json in ActiveRecord, I was wondering if maybe this stuff belonged in the model. Alternatively, does it belong in just a whole separate container somewhere? For what it's worth, users will be downloading models from the site, modifying them in excel, then posting them.

    Read the article

  • Ruby on Rails - Adding variable to params[]

    - by miligraf
    In the controller, how can I add a variable at the end of a params[]? If I try this I get an error: params[:group_] + variable How should it be done? Edit per request Ok, I have a form that sets groups of radio buttons with names like this: group_01DRN0 Obviously I have different groups in the form (group_01AAI0, group_01AUI0, etc.) and the value is set according to the radio button selected within the group: Radio button "group_01DRN0" could have value of "21" or "22" or "23", radio button "group_01AAI0" could have value of "21" or "22" or "23", etc. In the DB I have every code (01DRN0, 01AAI0, 01AUI0, etc) so I want to select them from DB and iterate in the params value so I can get the radio button group value, I've tried this with no luck: @codes=Code.get_codes for c in @codes @all=params[:group_] + c.name end Thanks.

    Read the article

  • Rails: Getting rid of generic "X is invalid" validation errors

    - by DJTripleThreat
    I have a sign-up form that has nested associations/attributes whatever you want to call them. My Hierarchy is this: class User < ActiveRecord::Base acts_as_authentic belongs_to :user_role, :polymorphic => true end class Customer < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attributes_for :user, :allow_destroy => true validates_associated :user end class Employee < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attributes_for :user, :allow_destroy => true validates_associated :user end I have some validation stuff in these classes as well. My problem is that if I try to create and Customer (or Employee etc) with a blank form I get all of the validation errors I should get plus some Generic ones like "User is invalid" and "Customer is invalid" If I iterate through the errors I get something like: user.login can't be blank User is invalid customer.whatever is blah blah blah...etc customer.some_other_error etc etc Since there is at least one invalid field in the nested User model, an extra "X is invalid" message is added to the list of errors. This gets confusing to my client and so I'm wondering if there is a quick way to do this instead of having to filer through the errors myself.

    Read the article

  • Rails form helper and RESTful routes

    - by Jimmy
    Hey guys, I have a form partial current setup like this to make new blog posts <% form_for([@current_user, @post]) do |f| %> This works great when editing a post, but when creating a new post I get the following error: undefined method `user_posts_path' for #<ActionView::Base:0x6158104> My routes are setup as follows: map.resources :user do |user| user.resources :post end Is there a better way to setup my partial to handle both new posts and editing current posts?

    Read the article

  • Ruby on Rails and database associations

    - by Marco
    Hi to all, I'm new to the Ruby world, and there is something unclear to me in defining associations between models. The question is: where is the association saved? For example, if i create a Customer model by executing: generate model Customer name:string age:integer and then i create an Order model generate model Order description:text quantity:integer and then i set the association in the following way: class Customer < ActiveRecord::Base has_many :orders end class Order < ActiveRecord::Base belongs_to :customer end I think here is missing something, for example the foreign key between the two entities. How does it handle the associations created with the keywords "has_many" and "belongs_to" ? Thanks

    Read the article

  • What caused the rails application crash?

    - by so1o
    I'm sure someone can explain this. we have an application that has been in production for an year. recently we saw an increase in number of support requests for people having difficulty signing into the system. after scratching our head because we couldn't recreate the problem in development, we decided we'll switch on debug logger in production for a month. that was june 5th. application worked fine with the above change and we were waiting. then yesterday we noticed that the log files were getting huge so we made another change in production config.logger = Logger.new("#{RAILS_ROOT}/log/production.log", 50, 1048576) after this change, the application started crashing while processing a particular file. this particular line of code was RAILS_DEFAULT_LOGGER.info "Payment Information Request: ", request.inspect as you can see there was a comma instead of a plus sign. this piece of code was introduced in Mar. the question is this: why did the application fail now? if changing the debug level caused the application to process this line of code it should have started failing on june 5th! why today. please someone help us. Are we missing the obvious here? if you dont have an answer, at least let us know we aren't the only one that are bonkers.

    Read the article

  • Test priorities on delayed_job plugin in rails.

    - by bartligthart
    I want to test how priorities are working in the delayed_job plugin. Im using the mailit app from railscasts. I think i want to send 100 messages with a high priority and 100 with a lower priority. And i want to see if the messages with a lower priority will be delivered on time or they will be put aside. How can i do a test like this.

    Read the article

  • Rails page caching and flash messages

    - by KJF
    I'm pretty sure I can page cache the vast majority of my site but the one thing preventing me from doing so is that my flash messages will not show, or they'll show at the wrong time. One thing I'm considering is writing the flash message to a cookie, reading it and displaying it via javascript and clearing the cookie once the message has been displayed. Has anyone had any success doing this or are there better methods? Thanks.

    Read the article

< Previous Page | 100 101 102 103 104 105 106 107 108 109 110 111  | Next Page >